Why are duplicate constructors being generated with C++

2 posts / 0 new
Last post
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

I have a constructor defined in a C++ file ( nothing else I can see )

SoftUART::SoftUART(uint8_t)
:
TxOut(true),
TxDataAvail(false),
RxDataAvail(false),
TxTickCnt(Oversamples),
TxState(TxIdle),
RxTickCnt(1),
RxState(RxIdle)
{
}

when I look in the generated listing file see two identical contructors with slightly different names but exactly the same code ( below ). Whats going on here and how do I eliminate the double code ?

.global _ZN8SoftUARTC2Eh
.type _ZN8SoftUARTC2Eh, @function
_ZN8SoftUARTC2Eh:
.stabn 68,0,9,.LM1-_ZN8SoftUARTC2Eh
.LM1:
/* prologue: frame size=0 */
/* prologue end (size=0) */
movw r30,r24
.stabn 68,0,17,.LM2-_ZN8SoftUARTC2Eh
.LM2:
.LBB2:
ld r24,Z
ori r24,lo8(1)
andi r24,lo8(-7)
st Z,r24
ldi r24,lo8(4)
std Z+2,r24
std Z+5,__zero_reg__
ldi r24,lo8(1)
std Z+7,r24
std Z+10,__zero_reg__
.stabn 68,0,18,.LM3-_ZN8SoftUARTC2Eh
.LM3:
.LBE2:
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function SoftUART::SoftUART(unsigned char) size 12 (11) */
.size _ZN8SoftUARTC2Eh, .-_ZN8SoftUARTC2Eh
.Lscope0:
.stabs "",36,0,0,.Lscope0-_ZN8SoftUARTC2Eh
.stabs "_ZN8SoftUARTC1Eh:F(0,21)",36,0,9,_ZN8SoftUARTC1Eh
.stabs "this:P(1,1)",64,0,9,30
.global _ZN8SoftUARTC1Eh
.type _ZN8SoftUARTC1Eh, @function
_ZN8SoftUARTC1Eh:
.stabn 68,0,9,.LM4-_ZN8SoftUARTC1Eh
.LM4:
/* prologue: frame size=0 */
/* prologue end (size=0) */
movw r30,r24
.stabn 68,0,17,.LM5-_ZN8SoftUARTC1Eh
.LM5:
.LBB3:
ld r24,Z
ori r24,lo8(1)
andi r24,lo8(-7)
st Z,r24
ldi r24,lo8(4)
std Z+2,r24
std Z+5,__zero_reg__
ldi r24,lo8(1)
std Z+7,r24
std Z+10,__zero_reg__
.stabn 68,0,18,.LM6-_ZN8SoftUARTC1Eh
.LM6:
.LBE3:
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function SoftUART::SoftUART(unsigned char) size 12 (11) */
.size _ZN8SoftUARTC1Eh, .-_ZN8SoftUARTC1Eh

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To demangle
c++filt _ZN8SoftUARTC2Eh
SoftUART::SoftUART[not-in-charge](unsigned char)
xc++filt _ZN8SoftUARTC1Eh
SoftUART::SoftUART[in-charge](unsigned char)

Re: C++ ABI: cloning of constructors/destructors

* To: dspezia at amadeus dot net
* Subject: Re: C++ ABI: cloning of constructors/destructors
* From: Nathan Sidwell
* Date: Mon, 09 Jul 2001 20:52:17 +0100
* CC: gcc at gcc dot gnu dot org
* Organization: Codesourcery LLC
* References:

dspezia@amadeus.net wrote:
>
> Hi all,
>
> I've just installed GCC 3.0 on a i386 linux box.
>
> Having a look at the code generated from a dummy C++
> program, it seems constructors and destructors are
> generated twice even for the simplest classes.
>
> I'm just curious: what is the purpose of this cloning process ?
See http://gcc.gnu.org/bugs.html#known, from which I quote

G++ emits two copies of constructors and destructors.

In general there are three types of constructors (and destructors).
1.The complete object constructor/destructor.
2.The base object constructor/destructor.
3.The allocating destructor/deallocating destructor.
The first two are different, when virtual base classes are involved. In some cases we can do better, and this is logged in GNATS.

nathan

--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

And from: http://www.codesourcery.com/cxx-abi/cxx-open.html

Two versions, and two entrypoints, of the constructor will be created: one that calls the virtual base subobject constructor (in-charge), and one that does not.