Makefile.in (CRTSTUFF_CFLAGS): Add -fno-zero-initialized-in-bss.

* Makefile.in (CRTSTUFF_CFLAGS): Add -fno-zero-initialized-in-bss.
	* doc/invoke.texi (-fno-zero-initialized-in-bss): Document.
	* flags.h (flag_zero_initialized_in_bss): Declare.
	* toplev.c (flag_zero_initialized_in_bss): New flag.
	(lang_independent_options): Add flag_zero_initialized_in_bss.
	* tree.c (initializer_zerop): New function.
	* tree.h (initializer_zerop): Declare.
	* varasm.c (assemble_variable): If we can emit bss, put zero
	initializers in the bss section.

From-SVN: r50218
This commit is contained in:
Kaveh R. Ghazi 2002-03-02 03:52:17 +00:00 committed by Kaveh Ghazi
parent ca734b39f3
commit 27b41650c1
8 changed files with 89 additions and 2 deletions

View File

@ -1,3 +1,15 @@
2002-03-01 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* Makefile.in (CRTSTUFF_CFLAGS): Add -fno-zero-initialized-in-bss.
* doc/invoke.texi (-fno-zero-initialized-in-bss): Document.
* flags.h (flag_zero_initialized_in_bss): Declare.
* toplev.c (flag_zero_initialized_in_bss): New flag.
(lang_independent_options): Add flag_zero_initialized_in_bss.
* tree.c (initializer_zerop): New function.
* tree.h (initializer_zerop): Declare.
* varasm.c (assemble_variable): If we can emit bss, put zero
initializers in the bss section.
2002-03-02 Alan Modra <amodra@bigpond.net.au>
* config/rs6000/rs6000.h (ASM_WEAKEN_DECL): AIX assembler doesn't

View File

@ -372,7 +372,8 @@ TARGET_LIBGCC2_CFLAGS =
# Options to use when compiling crtbegin/end.
CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
-finhibit-size-directive -fno-inline-functions -fno-exceptions
-finhibit-size-directive -fno-inline-functions -fno-exceptions \
-fno-zero-initialized-in-bss
# Additional sources to handle exceptions; overridden on ia64.
LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde.c \

View File

@ -273,6 +273,7 @@ in the following sections.
-fno-function-cse -fno-guess-branch-probability @gol
-fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol
-funsafe-math-optimizations -fno-trapping-math @gol
-fno-zero-initialized-in-bss @gol
-fomit-frame-pointer -foptimize-register-move @gol
-foptimize-sibling-calls -fprefetch-loop-arrays @gol
-freduce-all-givs -fregmove -frename-registers @gol
@ -3407,6 +3408,19 @@ an exact implementation of IEEE or ISO rules/specifications for
math functions.
The default is @option{-ftrapping-math}.
@item -fno-zero-initialized-in-bss
@opindex fno-zero-initialized-in-bss
If the target supports a BSS section, GCC by default puts variables that
are initialized to zero into BSS@. This can save space in the resulting
code.
This option turns off this behavior because some programs explicitly
rely on variables going to the data section. E.g., so that the
resulting executable can find the beginning of that section and/or make
assumptions based on that.
The default is @option{-fzero-initialized-in-bss}.
@end table
The following options control specific optimizations. The @option{-O2}

View File

@ -636,4 +636,7 @@ extern int flag_detailed_statistics;
/* Nonzero means enable synchronous exceptions for non-call instructions. */
extern int flag_non_call_exceptions;
/* Nonzero means put zero initialized data in the bss section. */
extern int flag_zero_initialized_in_bss;
#endif /* ! GCC_FLAGS_H */

View File

@ -803,6 +803,9 @@ int flag_gnu_linker = 0;
int flag_gnu_linker = 1;
#endif
/* Nonzero means put zero initialized data in the bss section. */
int flag_zero_initialized_in_bss = 1;
/* Enable SSA. */
int flag_ssa = 0;
@ -1135,6 +1138,8 @@ static const lang_independent_options f_options[] =
N_("Suppress output of instruction numbers and line number notes in debugging dumps") },
{"instrument-functions", &flag_instrument_function_entry_exit, 1,
N_("Instrument function entry/exit with profiling calls") },
{"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1,
N_("Put zero initialized data in the bss section") },
{"ssa", &flag_ssa, 1,
N_("Enable SSA optimizations") },
{"ssa-ccp", &flag_ssa_ccp, 1,

View File

@ -4975,3 +4975,45 @@ make_vector (mode, innertype, unsignedp)
return t;
}
/* Given an initializer INIT, return TRUE if INIT is zero or some
aggregate of zeros. Otherwise return FALSE. */
bool
initializer_zerop (init)
tree init;
{
STRIP_NOPS (init);
switch (TREE_CODE (init))
{
case INTEGER_CST:
return integer_zerop (init);
case REAL_CST:
return real_zerop (init)
&& ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
case COMPLEX_CST:
return integer_zerop (init)
|| (real_zerop (init)
&& ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
&& ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
case CONSTRUCTOR:
{
if (AGGREGATE_TYPE_P (TREE_TYPE (init)))
{
tree aggr_init = TREE_OPERAND (init, 1);
while (aggr_init)
{
if (! initializer_zerop (TREE_VALUE (aggr_init)))
return false;
aggr_init = TREE_CHAIN (aggr_init);
}
return true;
}
return false;
}
default:
return false;
}
}

View File

@ -2495,6 +2495,11 @@ extern int list_length PARAMS ((tree));
extern int fields_length PARAMS ((tree));
/* Given an initializer INIT, return TRUE if INIT is zero or some
aggregate of zeros. Otherwise return FALSE. */
extern bool initializer_zerop PARAMS ((tree));
/* integer_zerop (tree x) is nonzero if X is an integer constant of value 0 */
extern int integer_zerop PARAMS ((tree));

View File

@ -1608,7 +1608,12 @@ assemble_variable (decl, top_level, at_end, dont_output_data)
/* Handle uninitialized definitions. */
if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node
#if defined ASM_EMIT_BSS
|| (flag_zero_initialized_in_bss
&& initializer_zerop (DECL_INITIAL (decl)))
#endif
)
/* If the target can't output uninitialized but not common global data
in .bss, then we have to use .data. */
#if ! defined ASM_EMIT_BSS