diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-02-20 18:08:57 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-02-20 18:08:57 +0000 |
commit | 6b07a1c6ee50dcf4d52a4a314b4774347f9b22c0 (patch) | |
tree | 4cc8c21d84f5ad56ef4c8addf953a1cab14f5b5b | |
parent | 5c56fb55b0857181d7bb89c40cce9d87c0942c00 (diff) | |
download | bcm5719-llvm-6b07a1c6ee50dcf4d52a4a314b4774347f9b22c0.tar.gz bcm5719-llvm-6b07a1c6ee50dcf4d52a4a314b4774347f9b22c0.zip |
Add -funique-section-names and -fno-unique-section-names options.
For now -funique-section-names is the default, so no change in default behavior.
The total .o size in a build of llvm and clang goes from 241687775 to 230649031
bytes if -fno-unique-section-names is used.
llvm-svn: 230031
-rw-r--r-- | clang/include/clang/Driver/Options.td | 8 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CodeGenOptions.def | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 3 | ||||
-rw-r--r-- | clang/test/CodeGen/funique-sections.c | 13 | ||||
-rw-r--r-- | clang/test/Driver/function-sections.c | 12 |
7 files changed, 42 insertions, 0 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c4d3eda0978..434d546b208 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1004,6 +1004,14 @@ def fdata_sections : Flag <["-"], "fdata-sections">, Group<f_Group>, Flags<[CC1Option]>, HelpText<"Place each data in its own section (ELF Only)">; def fno_data_sections : Flag <["-"], "fno-data-sections">, Group<f_Group>, Flags<[CC1Option]>; + +def funique_section_names : Flag <["-"], "funique-section-names">, + Group<f_Group>, Flags<[CC1Option]>, + HelpText<"Use unique names for text and data sections (ELF Only)">; +def fno_unique_section_names : Flag <["-"], "fno-unique-section-names">, + Group<f_Group>, Flags<[CC1Option]>; + + def fdebug_types_section: Flag <["-"], "fdebug-types-section">, Group<f_Group>, Flags<[CC1Option]>, HelpText<"Place debug types in their own section (ELF Only)">; def fno_debug_types_section: Flag<["-"], "fno-debug-types-section">, Group<f_Group>, diff --git a/clang/include/clang/Frontend/CodeGenOptions.def b/clang/include/clang/Frontend/CodeGenOptions.def index adc69d99353..f14898fd189 100644 --- a/clang/include/clang/Frontend/CodeGenOptions.def +++ b/clang/include/clang/Frontend/CodeGenOptions.def @@ -40,6 +40,7 @@ CODEGENOPT(CXAAtExit , 1, 1) ///< Use __cxa_atexit for calling destructo CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker ///< aliases to base ctors when possible. CODEGENOPT(DataSections , 1, 0) ///< Set when -fdata-sections is enabled. +CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names. CODEGENOPT(DisableFPElim , 1, 0) ///< Set when -fomit-frame-pointer is enabled. CODEGENOPT(DisableFree , 1, 0) ///< Don't free memory. CODEGENOPT(DisableGCov , 1, 0) ///< Don't run the GCov pass, for testing. diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 7442f4374ca..da3e5ce6795 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -527,6 +527,7 @@ TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { Options.PositionIndependentExecutable = LangOpts.PIELevel != 0; Options.FunctionSections = CodeGenOpts.FunctionSections; Options.DataSections = CodeGenOpts.DataSections; + Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames; Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll; Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index b5f20608c14..dd878d0dfcd 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3316,6 +3316,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fdata-sections"); } + if (!Args.hasFlag(options::OPT_funique_section_names, + options::OPT_fno_unique_section_names, true)) + CmdArgs.push_back("-fno-unique-section-names"); + Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); if (Args.hasArg(options::OPT_fprofile_instr_generate) && diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 7a53cedc93b..bfd9429dace 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -472,6 +472,9 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, OPT_fno_function_sections, false); Opts.DataSections = Args.hasFlag(OPT_fdata_sections, OPT_fno_data_sections, false); + Opts.UniqueSectionNames = Args.hasFlag(OPT_funique_section_names, + OPT_fno_unique_section_names, true); + Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); diff --git a/clang/test/CodeGen/funique-sections.c b/clang/test/CodeGen/funique-sections.c new file mode 100644 index 00000000000..1473fe57db0 --- /dev/null +++ b/clang/test/CodeGen/funique-sections.c @@ -0,0 +1,13 @@ +// REQUIRES: x86-registered-target + +// RUN: %clang_cc1 -triple x86_64-pc-linux -S -ffunction-sections -fdata-sections -fno-unique-section-names -o - < %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-pc-linux -S -ffunction-sections -fdata-sections -o - < %s | FileCheck %s --check-prefix=UNIQUE + +const int hello = 123; +void world() {} + +// CHECK: .section .text,"ax",@progbits,unique +// CHECK: .section .rodata,"a",@progbits,unique + +// UNIQUE: .section .text.world,"ax",@progbits +// UNIQUE: .section .rodata.hello,"a",@progbits diff --git a/clang/test/Driver/function-sections.c b/clang/test/Driver/function-sections.c index fe6d303e3ec..ba065b1367a 100644 --- a/clang/test/Driver/function-sections.c +++ b/clang/test/Driver/function-sections.c @@ -4,6 +4,8 @@ // CHECK-NOFS-NOT: -ffunction-sections // CHECK-DS: -fdata-sections // CHECK-NODS-NOT: -fdata-sections +// CHECK-US-NOT: -fno-unique-section-names +// CHECK-NOUS: -fno-unique-section-names // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ // RUN: -target i386-unknown-linux \ @@ -60,3 +62,13 @@ // RUN: -fdata-sections -fno-data-sections -fdata-sections \ // RUN: | FileCheck --check-prefix=CHECK-DS %s + +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target i386-unknown-linux \ +// RUN: -funique-section-names \ +// RUN: | FileCheck --check-prefix=CHECK-US %s + +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target i386-unknown-linux \ +// RUN: -fno-unique-section-names \ +// RUN: | FileCheck --check-prefix=CHECK-NOUS %s |