]> granicus.if.org Git - clang/commitdiff
Enable -ffunction-sections and -fdata-sections for CloudABI by default.
authorEd Schouten <ed@nuxi.nl>
Thu, 26 Mar 2015 17:50:28 +0000 (17:50 +0000)
committerEd Schouten <ed@nuxi.nl>
Thu, 26 Mar 2015 17:50:28 +0000 (17:50 +0000)
Unlike most of the other platforms supported by Clang, CloudABI only
supports static linkage, for the reason that global filesystem access is
prohibited. Functions provided by dlfcn.h are not present. As we know
that applications will not try to do any symbol lookups at run-time, we
can garbage collect unused code quite aggressively. Because of this, it
makes sense to enable -ffunction-sections and -fdata-sections by
default.

Object files will be a bit larger than usual, but the resulting binary
will not be affected, as the sections are merged again. However, when
--gc-sections is used, the linker is able to remove unused code far more
more aggressively. It also has the advantage that transitive library
dependencies only need to be provided to the linker in case that
functionality is actually used.

Differential Revision: http://reviews.llvm.org/D8635
Reviewed by: echristo

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

lib/Driver/Tools.cpp
test/Driver/cloudabi.c
test/Driver/cloudabi.cpp

index 874484d35d7fecef57257f19021bd4ae132d224c..ed1bd3ef86884168b048a76d7dbd4a9c17ffc768 100644 (file)
@@ -3318,13 +3318,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-generate-type-units");
   }
 
+  // CloudABI uses -ffunction-sections and -fdata-sections by default.
+  bool UseSeparateSections = Triple.getOS() == llvm::Triple::CloudABI;
+
   if (Args.hasFlag(options::OPT_ffunction_sections,
-                   options::OPT_fno_function_sections, false)) {
+                   options::OPT_fno_function_sections, UseSeparateSections)) {
     CmdArgs.push_back("-ffunction-sections");
   }
 
   if (Args.hasFlag(options::OPT_fdata_sections,
-                   options::OPT_fno_data_sections, false)) {
+                   options::OPT_fno_data_sections, UseSeparateSections)) {
     CmdArgs.push_back("-fdata-sections");
   }
 
index 91c9e192e5b17f8c0c78d50fd6de676b03f6b2c7..99a2bc24f65341100df034e81d02dd7e9c3064b3 100644 (file)
@@ -1,3 +1,3 @@
 // RUN: %clang %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s
-// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi"
+// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"
 // CHECK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
index 8db3d85cb12b9f3515307026b25be66be53a64ab..c3b68ae88099cc6a0dd1eb1370ebf7d5dc86440a 100644 (file)
@@ -1,3 +1,3 @@
 // RUN: %clangxx %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s
-// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi"
+// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"
 // CHECK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc++" "-lc++abi" "-lunwind" "-lc" "-lcompiler_rt" "crtend.o"