i.e. there are global keyed constructors emitted for global objects which have
trivial constructors which just zero the contents of the object

e.g. 

gcc -Os foo.cxx of
---
static void * myPointer1(0);
void * myFunction1() { return myPointer1; }

struct MyStruct {
        void * pointer;
};

static MyStruct myPointer2;
---
and readelf -S foo.o | grep ctor
shows nothing, while...

gcc -Os foo.cxx of
---
struct MyOtherStruct {
        void * pointer;
        MyOtherStruct(): pointer(0) {}
};

static MyOtherStruct myPointer3;
---
gives an readelf -S foo.o | grep ctor
  [ 5] .ctors            PROGBITS         0000000000000000  00000070
  [ 6] .rela.ctors       RELA             0000000000000000  00000700

and 
nm foo.o | grep GLOBAL | c++filt | grep keyed | c++filt 
000000000000001c t global constructors keyed to foo.cxx_00000000_A20C6F19

It'd be neat if the global static MyOtherStruct myPointer3 ctor could be
optimized away.


-- 
           Summary: RFE: Possible to avoid emitting ctor sections for
                    trivial constructors of static objects ?
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: caolanm at redhat dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31785

Reply via email to