aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog12
-rw-r--r--gcc/Makefile.in3
-rw-r--r--gcc/doc/invoke.texi14
-rw-r--r--gcc/flags.h3
-rw-r--r--gcc/toplev.c5
-rw-r--r--gcc/tree.c42
-rw-r--r--gcc/tree.h5
-rw-r--r--gcc/varasm.c7
8 files changed, 89 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 22056f2..bd9ce0f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 604dd7d..5d1802f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -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 \
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 8dab7a0..10b69c8 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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}
diff --git a/gcc/flags.h b/gcc/flags.h
index 65353e6..6de5d9b 100644
--- a/gcc/flags.h
+++ b/gcc/flags.h
@@ -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 */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 83de908..7460582 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -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,
diff --git a/gcc/tree.c b/gcc/tree.c
index 5e0210b..de65191 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -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;
+ }
+}
diff --git a/gcc/tree.h b/gcc/tree.h
index b13fc53..68b96e8 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -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));
diff --git a/gcc/varasm.c b/gcc/varasm.c
index f8fb16c..e7505a8 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -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