Mac: set -obj_path_lto when building with LTO

This temporarily saves intermediate object files (other than cache hits
which are already persisted in the cache directory) so that `dsymutil`
can read the debug info out of them.

This change also adds an argument to linker_driver.py to clean this
directory up after `dsymutil` has run. I'm not sure this is the best
way to do it, so very open to other suggestions.

Bug: 1324104
Change-Id: I001e19b9824ff8bf969c5b713a3e0dbed52e5df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650843
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1004779}
NOKEYCHECK=True
GitOrigin-RevId: fb34ab468f55c8c383b31b341544627cb97efb25
diff --git a/compiler/BUILD.gn b/compiler/BUILD.gn
index c90821e..1817f17 100644
--- a/compiler/BUILD.gn
+++ b/compiler/BUILD.gn
@@ -680,9 +680,16 @@
       # of "all" which means number of hardware threads) is faster.
       ldflags += [ "-Wl,--thinlto-jobs=all" ]
       if (is_apple) {
-        ldflags +=
-            [ "-Wl,-cache_path_lto," +
-              rebase_path("$root_out_dir/thinlto-cache", root_build_dir) ]
+        # TODO(lgrey): Remove if/when we start running `dsymutil` through the
+        # clang driver. See https://crbug.com/1324104
+        object_path_lto =
+            rebase_path("$root_out_dir/lto-objects", root_build_dir)
+        ldflags += [
+          "-Wl,-cache_path_lto," +
+              rebase_path("$root_out_dir/thinlto-cache", root_build_dir),
+          "-Wl,-object_path_lto,$object_path_lto",
+          "-Wcrl,clean_object_path_lto,$object_path_lto",
+        ]
       } else {
         ldflags +=
             [ "-Wl,--thinlto-cache-dir=" +