diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d715d97dc4e..146eb18973b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2003-03-14 Jason Merrill + + PR optimization/6871 + * varasm.c (assemble_variable): Leave constant zeroes in .rodata. + 2003-03-14 Neil Booth * c-opts.c (finish_options): New. diff --git a/gcc/testsuite/gcc.dg/section1.c b/gcc/testsuite/gcc.dg/section1.c new file mode 100644 index 00000000000..e907f193b0f --- /dev/null +++ b/gcc/testsuite/gcc.dg/section1.c @@ -0,0 +1,5 @@ +/* PR optimization/6871 */ +/* Constant variables belong in .rodata, not .bss. */ +/* { dg-final { scan-assembler-not "\.bss" } } */ + +const int i = 0; diff --git a/gcc/varasm.c b/gcc/varasm.c index dea352a9097..42775dca5bc 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -1551,6 +1551,8 @@ assemble_variable (decl, top_level, at_end, dont_output_data) else if (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node || (flag_zero_initialized_in_bss + /* Leave constant zeroes in .rodata so they can be shared. */ + && !TREE_READONLY (decl) && initializer_zerop (DECL_INITIAL (decl)))) { unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);