[WebAssembly] Only enable --gc-sections when optimizations are enabled.

Also, revamp the wasm-toolchain.c test and add a test to ensure that
a user-supplied --no-gc-sections comes after --gc-sections.

llvm-svn: 257004
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 598ebc9..0236e61 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -6537,7 +6537,8 @@
 
   // Enable garbage collection of unused input sections by default, since code
   // size is of particular importance.
-  CmdArgs.push_back("--gc-sections");
+  if (areOptimizationsEnabled(Args))
+    CmdArgs.push_back("--gc-sections");
 
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
   CmdArgs.push_back("-o");