[Bug c/70306] New: wrong code at -O2 and -O3 in 32-bit and 64-bit mode on x86_64-linux-gnu [related to __attribute__((destructor)) and __attribute__((constructor))]

chengniansun at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Mar 19 07:16:00 GMT 2016


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

            Bug ID: 70306
           Summary: wrong code at -O2 and -O3 in 32-bit and 64-bit mode on
                    x86_64-linux-gnu [related to
                    __attribute__((destructor)) and
                    __attribute__((constructor))]
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com
  Target Milestone: ---

The following code is miscompiled by the trunk at -O2 and -O3 in 32-bit and
64-bit modes on x86_64-linux-gnu. 

This bug also affects gcc-5.1. 


$: gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 6.0.0 20160318 (experimental) [trunk revision 234347] (GCC) 
$: 
$: gcc-trunk -O1 small.c ; ./a.out
A
A
B
B
$: gcc-trunk -O2 small.c ; ./a.out
A
B
$: gcc-4.9 -O3 small.c ; ./a.out
A
A
B
B
$: 
$: cat small.c
int printf(const char *, ...);

__attribute__((constructor))
void A() { printf("A\n"); }

__attribute__((destructor))
void B() { printf("B\n"); }

__attribute__((constructor))
static void C() { printf("A\n"); }

__attribute__((destructor))
static void D() { printf("B\n"); }

int main() { return 0; }
$:


More information about the Gcc-bugs mailing list