https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69981

            Bug ID: 69981
           Summary: -f[no]keep-static-consts has no effect
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: equinox-gccbugs at diac24 dot net
  Target Milestone: ---

This bug is an extension of #20319; the -fkeep-static-consts option seems to
have no effect in either direction.  (#20319 was focused on the "-fkeep"
variant; my issue is with -O0 -fno-keep-static-consts.)

My application code is
extern struct foo ref;
static struct foo * const myconst = &ref;
Where ref is defined in a library that is not always linked in, which works on
-O1 -Og -Os -O2 -O3 but not on "-O0 -fno-keep-static-consts".  I think it
should.

Trying older versions, gcc-4.2.4 already behaves the same.


$ ./test.sh
gcc-4.9.3 -O0
0000000000000000 l     O .rodata        0000000000000004 intval
0000000000000000 l     O .data.rel.ro   0000000000000008 ptrval
gcc-4.9.3 -O0 -fkeep-static-consts
0000000000000000 l     O .rodata        0000000000000004 intval
0000000000000000 l     O .data.rel.ro   0000000000000008 ptrval
gcc-4.9.3 -O0 -fno-keep-static-consts
0000000000000000 l     O .rodata        0000000000000004 intval
0000000000000000 l     O .data.rel.ro   0000000000000008 ptrval
gcc-4.9.3 -O1
gcc-4.9.3 -O1 -fkeep-static-consts
gcc-4.9.3 -O1 -fno-keep-static-consts
gcc-5.3.0 -O0
0000000000000000 l     O .rodata        0000000000000004 intval
0000000000000000 l     O .data.rel.ro   0000000000000008 ptrval
gcc-5.3.0 -O0 -fkeep-static-consts
0000000000000000 l     O .rodata        0000000000000004 intval
0000000000000000 l     O .data.rel.ro   0000000000000008 ptrval
gcc-5.3.0 -O0 -fno-keep-static-consts
0000000000000000 l     O .rodata        0000000000000004 intval
0000000000000000 l     O .data.rel.ro   0000000000000008 ptrval
gcc-5.3.0 -O1
gcc-5.3.0 -O1 -fkeep-static-consts
gcc-5.3.0 -O1 -fno-keep-static-consts

$ cat test.sh
#!/bin/sh

cat >const.c <<EOF
static const int intval = 1234;

extern int dst;
static int * const ptrval = &dst;
EOF

for CC in gcc-4.9.3 gcc-5.3.0; do
        for OPT in -O0 -O1; do
                for ARG in "" "-fkeep-static-consts" "-fno-keep-static-consts";
do
                        echo $CC $OPT $ARG
                        $CC $OPT $ARG -o const.o -c const.c
                        objdump -t const.o | grep val
                done
        done
done

Reply via email to