[toolchain][go][mac] Support use_strip on Mac

llvm-objcopy doesn't support stripping Mach-O binaries currently. Use `xcrun
strip` to strip for clang-gn-built and go-built binaries.

Note that -x is used for .so in the C++ toolchain, but no args for C++
executables (equivalent to -u -r per `man strip` and recommended there).

However, on Go 1.10, strip of an executable causes the resulting binary to
segfault, and on Go 1.11, strip without -x fails citing "symbols referenced by
indirect symbol table entries that can't be stripped". So for Go, always use
`strip -x`.

DX-555 #comment
Test: Manual

Change-Id: I40f54b0f1e1628562fa84893bc3b708dc9e2f5cd
diff --git a/go/build.py b/go/build.py
index 78d476b..0cb0e3c 100755
--- a/go/build.py
+++ b/go/build.py
@@ -146,12 +146,17 @@
     retcode = subprocess.call(cmd, env=env)
 
     if retcode == 0 and args.unstripped_binname:
-      retcode = subprocess.call([os.path.join(args.toolchain_prefix,
-                                              'llvm-objcopy'),
-                                 '--strip-sections',
-                                 output_name,
-                                 stripped_output_name],
-                                env=env)
+        if args.current_os == 'mac':
+            retcode = subprocess.call(['xcrun', 'strip', '-x', output_name,
+                                       '-o', stripped_output_name],
+                                      env=env)
+        else:
+            retcode = subprocess.call([os.path.join(args.toolchain_prefix,
+                                                    'llvm-objcopy'),
+                                       '--strip-sections',
+                                       output_name,
+                                       stripped_output_name],
+                                      env=env)
 
     if retcode == 0:
         if args.depfile is not None:
diff --git a/toolchain/clang_toolchain.gni b/toolchain/clang_toolchain.gni
index d72d768..501950c 100644
--- a/toolchain/clang_toolchain.gni
+++ b/toolchain/clang_toolchain.gni
@@ -93,7 +93,11 @@
 
     forward_variables_from(invoker, [ "use_strip" ])
     if (use_strip) {
-      strip = "${prefix}/llvm-objcopy"
+      if (invoker.toolchain_os == "mac") {
+        strip = "xcrun strip"
+      } else {
+        strip = "${prefix}/llvm-objcopy"
+      }
     }
 
     # Override any tools as requested by the invoker
@@ -198,7 +202,12 @@
         default_output_extension = ".so"
       }
       if (use_strip) {
-        command += " && $strip --strip-all \"$unstripped_outfile\" \"$outfile\""
+        if (invoker.toolchain_os == "mac") {
+          command += " && $strip -x \"$unstripped_outfile\" -o \"$outfile\""
+        } else {
+          command +=
+              " && $strip --strip-all \"$unstripped_outfile\" \"$outfile\""
+        }
       }
       description = "SOLINK $outfile"
       default_output_dir = "{{root_out_dir}}"
@@ -230,7 +239,12 @@
         default_output_extension = ".so"
       }
       if (use_strip) {
-        command += " && $strip --strip-all \"$unstripped_outfile\" \"$outfile\""
+        if (invoker.toolchain_os == "mac") {
+          command += " && $strip -x \"$unstripped_outfile\" -o \"$outfile\""
+        } else {
+          command +=
+              " && $strip --strip-all \"$unstripped_outfile\" \"$outfile\""
+        }
       }
       description = "SOLINK $outfile"
       default_output_dir = "{{root_out_dir}}"
@@ -257,8 +271,12 @@
         rspfile_content = "{{inputs}}"
       }
       if (use_strip) {
-        command +=
-            " && $strip --strip-sections \"$unstripped_outfile\" \"$outfile\""
+        if (invoker.toolchain_os == "mac") {
+          command += " && $strip \"$unstripped_outfile\" -o \"$outfile\""
+        } else {
+          command +=
+              " && $strip --strip-sections \"$unstripped_outfile\" \"$outfile\""
+        }
       }
       description = "LINK $outfile"
       default_output_dir = "{{root_out_dir}}"