6

Consider the following files

foo.h

class Foo
{
  Foo();
  Foo(int x);
  void bar();
}

foo.cc

# include foo.h

Foo::Foo() {}
Foo::Foo(int x) {}
void Foo::bar() {}

When compiling these files to LLVM bitcode foo.bc as follows

clang++ -c -o foo.bc -emit-llvm foo.cc

the resulting LLVM bitcode file, foo.bc contains two symbols for every constructor definition but only one symbol for the function definition. Why is this?

I have tested this on both LLVM versions 3.4 and 4.0.1, and the behaviour occurs with both versions. For reference, here is the output of

llvm-nm foo.bc

T _ZN3Foo3barEv
T _ZN3FooC1Ei
T _ZN3FooC1Ev
T _ZN3FooC2Ei
T _ZN3FooC2Ev

-- Edit --

Based on milleniumbug's comment below, here is some additional information on complete object constructors:

apaderno
  • 28,547
  • 16
  • 75
  • 90
UnchartedWaters
  • 522
  • 1
  • 4
  • 14
  • 6
    Check out the [Itanium C++ ABI](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-special-ctor-dtor): the one with C1 is a "complete object constructor" and C2 is a "base object constructor". (exercise for people trying to answer this question: find out why two separate definitions are needed) – milleniumbug Jul 23 '17 at 16:55
  • You're allowed to answer your own question - and a summary here would be much better than just posting a link. – Alan Stokes Jul 23 '17 at 17:28

0 Answers0