remote_link: pass --target and -m flags to codegen

Clang uses a default target tuple when not told explicitly which
target to generate code for. This may not match the target we are
actually building for. To set the correct target, we pass the
--target=... parameter. This change makes remote_link.py pass
this parameter on to the code generation commands it generates.
Similarly, there are many command line parameters that start in
"-m" which are also relevant to code generation, so this change
makes remote_link pass those on, as well.

Bug: 1507029

Change-Id: I41f65d70fc32b5c628b31a0fd9492993a1a22480
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5079899
Commit-Queue: Bob Haarman <inglorion@chromium.org>
Reviewed-by: Amy Huang <akhuang@google.com>
Cr-Commit-Position: refs/heads/main@{#1239376}
diff --git a/tools/clang/scripts/remote_link.py b/tools/clang/scripts/remote_link.py
index 7aafa0c8..62a27d80 100755
--- a/tools/clang/scripts/remote_link.py
+++ b/tools/clang/scripts/remote_link.py
@@ -224,6 +224,11 @@
       return [param]
     if param.startswith('-g'):
       return [param]
+    if param.startswith('-m'):
+      # Note: -mllvm is handled separately above.
+      return [param]
+    if param.startswith('--target'):
+      return [param]
     return None
 
   def output_path(self, args):
diff --git a/tools/clang/scripts/remote_link_unit_tests.py b/tools/clang/scripts/remote_link_unit_tests.py
index f177865..aac44f0a 100755
--- a/tools/clang/scripts/remote_link_unit_tests.py
+++ b/tools/clang/scripts/remote_link_unit_tests.py
@@ -98,14 +98,17 @@
   def test_analyze_expanded_args_params(self):
     with FakeFs(bitcode_files=['foo.o']):
       result = remote_ld.RemoteLinkUnix().analyze_expanded_args([
-          'clang', '-O2', '-flto=thin', '-fsplit-lto-unit',
-          '-fwhole-program-vtables', '-fsanitize=cfi', '-g', '-gsplit-dwarf',
-          '-mllvm', '-generate-type-units', 'foo.o', '-o', 'foo'
+          'clang', '-O2', '--target=arm-none-eabi', '-march=armv7-a',
+          '-flto=thin', '-fsplit-lto-unit', '-fwhole-program-vtables',
+          '-fsanitize=cfi', '-g', '-gsplit-dwarf', '-mllvm',
+          '-generate-type-units', 'foo.o', '-o', 'foo'
       ], 'foo', 'clang', 'lto.foo', 'common', False)
       self.assertIsNotNone(result)
       self.assertIn('-Wl,-plugin-opt=obj-path=lto.foo/foo.split.o',
                     result.index_params)
       self.assertIn('-O2', result.index_params)
+      self.assertIn('--target=arm-none-eabi', result.codegen_params)
+      self.assertIn('-march=armv7-a', result.codegen_params)
       self.assertIn('-g', result.index_params)
       self.assertIn('-gsplit-dwarf', result.index_params)
       self.assertIn('-mllvm -generate-type-units',
@@ -115,7 +118,8 @@
       self.assertIn('-fsanitize=cfi', result.index_params)
 
       self.assertIn('-O2', result.codegen_params)
-      self.assertIn('-g', result.codegen_params)
+      self.assertIn('--target=arm-none-eabi', result.codegen_params)
+      self.assertIn('-march=armv7-a', result.codegen_params)
       self.assertIn('-gsplit-dwarf', result.codegen_params)
       self.assertIn('-mllvm -generate-type-units',
                     ' '.join(result.codegen_params))