]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Only enable --gc-sections when optimizations are enabled.
authorDan Gohman <dan433584@gmail.com>
Thu, 7 Jan 2016 00:32:04 +0000 (00:32 +0000)
committerDan Gohman <dan433584@gmail.com>
Thu, 7 Jan 2016 00:32:04 +0000 (00:32 +0000)
Also, revamp the wasm-toolchain.c test and add a test to ensure that
a user-supplied --no-gc-sections comes after --gc-sections.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257004 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/wasm-toolchain.c

index 598ebc955ee0b735798cb452143d76aeecb3a763..0236e613a37ead0ddf3c010b0580601552132ffc 100644 (file)
@@ -6537,7 +6537,8 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   // 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");
index 78cb711145541f676deb3b4b31278689afd7f1e1..82c0c5828be5836422461d9563dfa2454545ee27 100644 (file)
@@ -1,3 +1,23 @@
-// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown -x assembler %s 2>&1 | FileCheck -check-prefix=AS_LINK %s
-// AS_LINK: clang{{.*}}" "-cc1as" {{.*}} "-o" "[[temp:[^"]*]]"
-// AS_LINK: lld{{.*}}" "-flavor" "ld" "--gc-sections" "[[temp]]" "-o" "a.out"
+// A basic clang -cc1 command-line.
+
+// RUN: %clang %s -### -target wasm32-unknown-unknown 2>&1 | FileCheck -check-prefix=CC1 %s
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}}
+
+// A basic C link command-line.
+
+// RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown %s 2>&1 | FileCheck -check-prefix=LINK %s
+// LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK: lld{{.*}}" "-flavor" "ld" "[[temp]]" "-o" "a.out"
+
+// A basic C link command-line with optimization.
+
+// RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
+// LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_OPT: lld{{.*}}" "-flavor" "ld" "--gc-sections" "[[temp]]" "-o" "a.out"
+
+// Ditto, but ensure that a user --no-gc-sections comes after the
+// default --gc-sections.
+
+// RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown -Wl,--no-gc-sections %s 2>&1 | FileCheck -check-prefix=NO_GC_SECTIONS %s
+// NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "ld" "--gc-sections" "--no-gc-sections" "[[temp]]" "-o" "a.out"