<p dir="ltr">Want to add the gc-sections to the linker as part of this?</p>
<br><div class="gmail_quote">On Thu, Mar 26, 2015, 8:38 AM Ed Schouten <<a href="mailto:ed@nuxi.nl">ed@nuxi.nl</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi echristo,<br>
<br>
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.<br>
<br>
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.<br>
<br>
REPOSITORY<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D8635" target="_blank">http://reviews.llvm.org/D8635</a><br>
<br>
Files:<br>
  lib/Driver/Tools.cpp<br>
  test/Driver/cloudabi.c<br>
  test/Driver/cloudabi.cpp<br>
<br>
Index: lib/Driver/Tools.cpp<br>
==============================<u></u>==============================<u></u>=======<br>
--- lib/Driver/Tools.cpp<br>
+++ lib/Driver/Tools.cpp<br>
@@ -3318,13 +3318,18 @@<br>
     CmdArgs.push_back("-generate-<u></u>type-units");<br>
   }<br>
<br>
+  // CloudABI only supports static linkage. Simplify the library<br>
+  // dependency tree and reduce binary size by using -ffunction-sections<br>
+  // and -fdata-sections by default.<br>
+  bool UseSeparateSections = Triple.getOS() == llvm::Triple::CloudABI;<br>
+<br>
   if (Args.hasFlag(options::OPT_<u></u>ffunction_sections,<br>
-                   options::OPT_fno_function_<u></u>sections, false)) {<br>
+                   options::OPT_fno_function_<u></u>sections, UseSeparateSections)) {<br>
     CmdArgs.push_back("-ffunction-<u></u>sections");<br>
   }<br>
<br>
   if (Args.hasFlag(options::OPT_<u></u>fdata_sections,<br>
-                   options::OPT_fno_data_<u></u>sections, false)) {<br>
+                   options::OPT_fno_data_<u></u>sections, UseSeparateSections)) {<br>
     CmdArgs.push_back("-fdata-<u></u>sections");<br>
   }<br>
<br>
Index: test/Driver/cloudabi.c<br>
==============================<u></u>==============================<u></u>=======<br>
--- test/Driver/cloudabi.c<br>
+++ test/Driver/cloudabi.c<br>
@@ -1,3 +1,3 @@<br>
 // RUN: %clang %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s<br>
-// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi"<br>
+// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"<br>
 // CHECK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"<br>
Index: test/Driver/cloudabi.cpp<br>
==============================<u></u>==============================<u></u>=======<br>
--- test/Driver/cloudabi.cpp<br>
+++ test/Driver/cloudabi.cpp<br>
@@ -1,3 +1,3 @@<br>
 // RUN: %clangxx %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s<br>
-// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi"<br>
+// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"<br>
 // CHECK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc++" "-lc++abi" "-lunwind" "-lc" "-lcompiler_rt" "crtend.o"<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/<u></u>settings/panel/<u></u>emailpreferences/</a><br>
</blockquote></div>