Re: constructors/destructors compiled twice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kövesdi György wrote:
> Hi,
> 
> I would like to use C++ for 8-bit AVR CPUs, so saving space would be 
> important.
> I found that the constructors and destructors always have two instances, which 
> are exactly the same. I tried it for X86, X86/64, M68k, and AVR platforms, 
> with the same result, so it is not platform-dependent.
> 
> Here is a disassembled example:
> 
> 000000f8 <valami::valami()>:
>   f8:   fc 01           movw    r30, r24
>   fa:   84 e0           ldi r24, 0x04   ; 4
>   fc:   91 e0           ldi r25, 0x01   ; 1
>   fe:   91 83           std Z+1, r25    ; 0x01
>  100:   80 83           st  Z, r24
>  102:   13 82           std Z+3, r1 ; 0x03
>  104:   12 82           std Z+2, r1 ; 0x02
>  106:   08 95           ret
> 
> 00000108 <valami::valami()>:
>  108:   fc 01           movw    r30, r24
>  10a:   84 e0           ldi r24, 0x04   ; 4
>  10c:   91 e0           ldi r25, 0x01   ; 1
>  10e:   91 83           std Z+1, r25    ; 0x01
>  110:   80 83           st  Z, r24
>  112:   13 82           std Z+3, r1 ; 0x03
>  114:   12 82           std Z+2, r1 ; 0x02
>  116:   08 95           ret
> 
> Is it possible to switch off this behavior?

AFAIR gcc produces up to three versions of a constructor (internally
named somewhat with C1, C2, C3) which are invoked for different
situations (e.g. being a derived or superclass in a class hierachy that
uses virtual functions or even virtual derivation.).

I don't know the exact details, but assume that if one of these
situations is not the case, gcc still produces all versions of the
constructor even though the resulting machine code is identical.

To proof this theory you might want to take a look at the generated
symbol names without demangling them. They should be different.

If that is the case you might try compiling with -ffunction-sections and
linking with --gc-sections. I suppose you are not using virtual
functions, so  either version is not actually used and the linker
removes it during garbage collection.


Daniel



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux