[PATCH] D24644: Pass -ffunction-sections/-fdata-sections along to gold-plugin

Teresa Johnson via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 13 11:15:07 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL284140: Pass -ffunction-sections/-fdata-sections along to gold-plugin (authored by tejohnson).

Changed prior to commit:
  https://reviews.llvm.org/D24644?vs=71591&id=74555#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24644

Files:
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/test/Driver/gold-lto-sections.c


Index: cfe/trunk/lib/Driver/Tools.cpp
===================================================================
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -2002,6 +2002,14 @@
   return Parallelism;
 }
 
+// CloudABI and WebAssembly use -ffunction-sections and -fdata-sections by
+// default.
+static bool isUseSeparateSections(const llvm::Triple &Triple) {
+  return Triple.getOS() == llvm::Triple::CloudABI ||
+         Triple.getArch() == llvm::Triple::wasm32 ||
+         Triple.getArch() == llvm::Triple::wasm64;
+}
+
 static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,
                           ArgStringList &CmdArgs, bool IsThinLTO,
                           const Driver &D) {
@@ -2051,6 +2059,19 @@
     else
       CmdArgs.push_back("-plugin-opt=-debugger-tune=gdb");
   }
+
+  bool UseSeparateSections =
+      isUseSeparateSections(ToolChain.getEffectiveTriple());
+
+  if (Args.hasFlag(options::OPT_ffunction_sections,
+                   options::OPT_fno_function_sections, UseSeparateSections)) {
+    CmdArgs.push_back("-plugin-opt=-function-sections");
+  }
+
+  if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
+                   UseSeparateSections)) {
+    CmdArgs.push_back("-plugin-opt=-data-sections");
+  }
 }
 
 /// This is a helper function for validating the optional refinement step
@@ -4763,11 +4784,7 @@
     CmdArgs.push_back("-generate-type-units");
   }
 
-  // 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;
+  bool UseSeparateSections = isUseSeparateSections(Triple);
 
   if (Args.hasFlag(options::OPT_ffunction_sections,
                    options::OPT_fno_function_sections, UseSeparateSections)) {
Index: cfe/trunk/test/Driver/gold-lto-sections.c
===================================================================
--- cfe/trunk/test/Driver/gold-lto-sections.c
+++ cfe/trunk/test/Driver/gold-lto-sections.c
@@ -0,0 +1,8 @@
+// RUN: touch %t.o
+//
+// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \
+// RUN:     -Wl,-plugin-opt=foo -O3 \
+// RUN:     -ffunction-sections -fdata-sections \
+// RUN:     | FileCheck %s
+// CHECK: "-plugin-opt=-function-sections"
+// CHECK: "-plugin-opt=-data-sections"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24644.74555.patch
Type: text/x-patch
Size: 2497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161013/9c69b233/attachment-0001.bin>


More information about the cfe-commits mailing list