]> granicus.if.org Git - clang/commitdiff
add frontend support for -fdata-sections and -ffunction-sections,
authorChris Lattner <sabre@nondot.org>
Tue, 13 Apr 2010 00:38:24 +0000 (00:38 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 13 Apr 2010 00:38:24 +0000 (00:38 +0000)
patch by Sylvere Teissier!

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

include/clang/CodeGen/CodeGenOptions.h
include/clang/Driver/CC1Options.td
lib/Frontend/CodeGenAction.cpp
lib/Frontend/CompilerInvocation.cpp

index 638ed516ed0b870eb4245a3630bdff7922402a54..51b9c57f2c65ffee157ab2f4bb131823609fb988 100644 (file)
@@ -32,6 +32,7 @@ public:
   unsigned CXAAtExit         : 1; /// Use __cxa_atexit for calling destructors.
   unsigned CXXCtorDtorAliases: 1; /// Emit complete ctors/dtors as linker
                                   /// aliases to base ctors when possible.
+  unsigned DataSections      : 1; /// Set when -fdata-sections is enabled
   unsigned DebugInfo         : 1; /// Should generate deubg info (-g).
   unsigned DisableFPElim     : 1; /// Set when -fomit-frame-pointer is enabled.
   unsigned DisableLLVMOpts   : 1; /// Don't run any optimizations, for use in
@@ -39,6 +40,7 @@ public:
                                   /// internal state before optimizations are
                                   /// done.
   unsigned DisableRedZone    : 1; /// Set when -mno-red-zone is enabled.
+  unsigned FunctionSections  : 1; /// Set when -ffunction-sections is enabled
   unsigned MergeAllConstants : 1; /// Merge identical constants.
   unsigned NoCommon          : 1; /// Set when -fno-common or C++ is enabled.
   unsigned NoImplicitFloat   : 1; /// Set when -mno-implicit-float is enabled.
@@ -88,10 +90,12 @@ public:
     AsmVerbose = 0;
     CXAAtExit = 1;
     CXXCtorDtorAliases = 0;
+    DataSections = 0;
     DebugInfo = 0;
     DisableFPElim = 0;
     DisableLLVMOpts = 0;
     DisableRedZone = 0;
+    FunctionSections = 0;
     MergeAllConstants = 1;
     NoCommon = 0;
     NoImplicitFloat = 0;
index 74e9b8694e08fd351901106dedb2cc21650f5a6e..542bde6b3230abf0cf862447474f226b665c5df8 100644 (file)
@@ -123,6 +123,10 @@ def fno_threadsafe_statics : Flag<"-fno-threadsafe-statics">,
   HelpText<"Do not emit code to make initialization of local statics thread safe">;
 def fdump_vtable_layouts : Flag<"-fdump-vtable-layouts">,
   HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">;
+def ffunction_sections : Flag<"-ffunction-sections">,
+  HelpText<"Place each function in its own section (ELF Only)">;
+def fdata_sections : Flag<"-fdata-sections">,
+  HelpText<"Place each data in its own section (ELF Only)">;
 def masm_verbose : Flag<"-masm-verbose">,
   HelpText<"Generate verbose assembly output">;
 def mcode_model : Separate<"-mcode-model">,
index 7ed702ed5112951a702a1cc70b7198bf6f5f9bcb..fdce21170e315bff17fa3d19de320d3cd76e3b35 100644 (file)
@@ -261,6 +261,9 @@ bool BackendConsumer::AddEmitPasses() {
 
   TargetMachine::setAsmVerbosityDefault(CodeGenOpts.AsmVerbose);
 
+  TargetMachine::setFunctionSections(CodeGenOpts.FunctionSections);
+  TargetMachine::setDataSections    (CodeGenOpts.DataSections);
+
   // FIXME: Parse this earlier.
   if (CodeGenOpts.RelocationModel == "static") {
     TargetMachine::setRelocationModel(llvm::Reloc::Static);
index 17007b00796b513c79304db2891f9093d5e203e6..b5e56458779832b86d8f46bc7caec86752ca225c 100644 (file)
@@ -148,6 +148,10 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
   // VerifyModule is only derived.
   // Inlining is only derived.
 
+  if (Opts.DataSections)
+    Res.push_back("-fdata-sections");
+  if (Opts.FunctionSections)
+    Res.push_back("-ffunction-sections");
   if (Opts.AsmVerbose)
     Res.push_back("-masm-verbose");
   if (!Opts.CodeModel.empty()) {
@@ -803,6 +807,9 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
   Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
   Opts.RelocationModel = getLastArgValue(Args, OPT_mrelocation_model, "pic");
 
+  Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
+  Opts.DataSections = Args.hasArg(OPT_fdata_sections);
+
   Opts.MainFileName = getLastArgValue(Args, OPT_main_file_name);
   Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);
 }