From ff05979144fc199e229aaeb1d248867d87d0d866 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 11 Oct 2013 03:35:10 +0000 Subject: [PATCH] Add -fno-function-sections and -fno-data-sections. Since -f{function,data}-sections had no tests at all, add some, and verify that the -fno variants work as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192413 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 13 +++++++++---- lib/Frontend/CompilerInvocation.cpp | 6 ++++-- test/CodeGen/sections.c | 26 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 test/CodeGen/sections.c diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 7ca2547f30..268f481b7c 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -832,10 +832,15 @@ def fwrapv : Flag<["-"], "fwrapv">, Group, Flags<[CC1Option]>, def fwritable_strings : Flag<["-"], "fwritable-strings">, Group, Flags<[CC1Option]>, HelpText<"Store string literals as writable data">; def fzero_initialized_in_bss : Flag<["-"], "fzero-initialized-in-bss">, Group; -def ffunction_sections: Flag <["-"], "ffunction-sections">, Group, - Flags<[CC1Option]>, HelpText<"Place each function in its own section (ELF Only)">; -def fdata_sections : Flag <["-"], "fdata-sections">, Group, Flags<[CC1Option]>, - HelpText<"Place each data in its own section (ELF Only)">; +def ffunction_sections : Flag<["-"], "ffunction-sections">, Group, + Flags<[CC1Option]>, + HelpText<"Place each function in its own section (ELF Only)">; +def fno_function_sections : Flag<["-"], "fno-function-sections">, + Group, Flags<[CC1Option]>; +def fdata_sections : Flag <["-"], "fdata-sections">, Group, + Flags<[CC1Option]>, HelpText<"Place each data in its own section (ELF Only)">; +def fno_data_sections : Flag <["-"], "fno-data-sections">, Group, + Flags<[CC1Option]>; def fdebug_types_section: Flag <["-"], "fdebug-types-section">, Group, Flags<[CC1Option]>, HelpText<"Place debug types in their own section (ELF Only)">; def g_Flag : Flag<["-"], "g">, Group, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 38a4b9531a..94fd4b53a6 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -398,8 +398,10 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ); Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array); - Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections); - Opts.DataSections = Args.hasArg(OPT_fdata_sections); + Opts.FunctionSections = Args.hasFlag(OPT_ffunction_sections, + OPT_fno_function_sections, false); + Opts.DataSections = Args.hasFlag(OPT_fdata_sections, + OPT_fno_data_sections, false); Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive); Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops); diff --git a/test/CodeGen/sections.c b/test/CodeGen/sections.c new file mode 100644 index 0000000000..c03391f50a --- /dev/null +++ b/test/CodeGen/sections.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -o - < %s | FileCheck %s --check-prefix=PLAIN +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -ffunction-sections -fno-function-sections -o - < %s | FileCheck %s --check-prefix=PLAIN + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -ffunction-sections -o - < %s | FileCheck %s --check-prefix=FUNC_SECT +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fno-function-sections -ffunction-sections -o - < %s | FileCheck %s --check-prefix=FUNC_SECT + +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fno-data-sections -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT + +const int hello = 123; +void world() {} + +// PLAIN-NOT: section +// PLAIN: world: +// PLAIN: section .rodata, +// PLAIN: hello: + +// FUNC_SECT: section .text.world, +// FUNC_SECT: world: +// FUNC_SECT: section .rodata, +// FUNC_SECT: hello: + +// DATA_SECT-NOT: section +// DATA_SECT: world: +// DATA_SECT: .section .rodata.hello, +// DATA_SECT: hello: -- 2.40.0