pw_toolchain: Move --gc-sections

Moves the --gc-sections and -dead_strip flags from
generate_toolchain.gni to a pw_build config so it lives alongside
similar size-reduction flags.

Change-Id: Ie4a51a9357a41ecd997eba28bfa78ddf43471b72
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/89146
Pigweed-Auto-Submit: Armando Montanez <amontanez@google.com>
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_build/BUILD.gn b/pw_build/BUILD.gn
index a6d0cd7..1a74c2b 100644
--- a/pw_build/BUILD.gn
+++ b/pw_build/BUILD.gn
@@ -70,6 +70,14 @@
     "-fdata-sections",
   ]
   cflags_cc = [ "-fno-rtti" ]
+
+  if (current_os == "mac" || current_os == "ios") {
+    # Delete unreferenced sections. Helpful with -ffunction-sections.
+    ldflags = [ "-Wl,-dead_strip" ]
+  } else {
+    # Delete unreferenced sections. Helpful with -ffunction-sections.
+    ldflags = [ "-Wl,--gc-sections" ]
+  }
 }
 
 config("strict_warnings") {
diff --git a/pw_toolchain/generate_toolchain.gni b/pw_toolchain/generate_toolchain.gni
index ce925be..db057c2 100644
--- a/pw_toolchain/generate_toolchain.gni
+++ b/pw_toolchain/generate_toolchain.gni
@@ -251,17 +251,11 @@
         _link_flags += [
           # Output a map file that shows symbols and their location.
           "-Wl,-map,$_link_mapfile",
-
-          # Delete unreferenced sections. Helpful with -ffunction-sections.
-          "-Wl,-dead_strip",
         ]
       } else {
         _link_flags += [
           # Output a map file that shows symbols and their location.
           "-Wl,-Map,$_link_mapfile",
-
-          # Delete unreferenced sections. Helpful with -ffunction-sections.
-          "-Wl,--gc-sections",
         ]
       }