r257005 - [WebAssembly] Enable -ffunction-sections and -fdata-sections by default.

Dan Gohman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 6 16:50:27 PST 2016


Author: djg
Date: Wed Jan  6 18:50:27 2016
New Revision: 257005

URL: http://llvm.org/viewvc/llvm-project?rev=257005&view=rev
Log:
[WebAssembly] Enable -ffunction-sections and -fdata-sections by default.

These remain user-overridable with -fno-function-sections and
-fno-data-sections.

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/wasm-toolchain.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=257005&r1=257004&r2=257005&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Jan  6 18:50:27 2016
@@ -4176,8 +4176,11 @@ void Clang::ConstructJob(Compilation &C,
     CmdArgs.push_back("-generate-type-units");
   }
 
-  // CloudABI uses -ffunction-sections and -fdata-sections by default.
-  bool UseSeparateSections = Triple.getOS() == llvm::Triple::CloudABI;
+  // CloudABI and WebAssembly use -ffunction-sections and -fdata-sections by
+  // default.
+  bool UseSeparateSections = Triple.getOS() == llvm::Triple::CloudABI ||
+                             Triple.getArch() == llvm::Triple::wasm32 ||
+                             Triple.getArch() == llvm::Triple::wasm64;
 
   if (Args.hasFlag(options::OPT_ffunction_sections,
                    options::OPT_fno_function_sections, UseSeparateSections)) {
@@ -6536,7 +6539,9 @@ void wasm::Linker::ConstructJob(Compilat
   CmdArgs.push_back("ld");
 
   // Enable garbage collection of unused input sections by default, since code
-  // size is of particular importance.
+  // size is of particular importance. This is significantly facilitated by
+  // the enabling of -ffunction-sections and -fdata-sections in
+  // Clang::ConstructJob.
   if (areOptimizationsEnabled(Args))
     CmdArgs.push_back("--gc-sections");
 

Modified: cfe/trunk/test/Driver/wasm-toolchain.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.c?rev=257005&r1=257004&r2=257005&view=diff
==============================================================================
--- cfe/trunk/test/Driver/wasm-toolchain.c (original)
+++ cfe/trunk/test/Driver/wasm-toolchain.c Wed Jan  6 18:50:27 2016
@@ -1,7 +1,19 @@
 // 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" {{.*}}
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-ffunction-sections" "-fdata-sections"
+
+// Ditto, but ensure that a user -fno-function-sections disables the
+// default -ffunction-sections.
+
+// RUN: %clang %s -### -target wasm32-unknown-unknown -fno-function-sections 2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
+// NO_FUNCTION_SECTIONS-NOT: function-sections
+
+// Ditto, but ensure that a user -fno-data-sections disables the
+// default -fdata-sections.
+
+// RUN: %clang %s -### -target wasm32-unknown-unknown -fno-data-sections 2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
+// NO_DATA_SECTIONS-NOT: data-sections
 
 // A basic C link command-line.
 




More information about the cfe-commits mailing list