5

When compiled, this:

template <typename T>
struct ConstArray {
///MEMBERS
    T* data_;
    T* end_;

///Constructors
    ConstArray(T* data, T* end) : data_(data), end_(end) {}
};

template struct ConstArray<const char>;

gives me (nm -C *.o):

0000000000000000 W ConstArray<char const>::ConstArray(char const*, char const*)
0000000000000000 W ConstArray<char const>::ConstArray(char const*, char const*)
0000000000000000 n ConstArray<char const>::ConstArray(char const*, char const*)

I seem to get three symbols (2 W + 1 n (don't know what that is)) for each constructor I define. Functions seem to give me just one as expected. Could somebody please explain why this is or point me to an explanation?

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • 7
    Seems relevant: http://stackoverflow.com/questions/6921295/dual-emission-of-constructor-symbols – Michael Sep 23 '15 at 11:30
  • yepp, just found it https://www.google.com/search?q=multiple+constructors+generated and there was another great answer somewhere, I just don't know what search words to use. – Karoly Horvath Sep 23 '15 at 11:31
  • @Michael Thanks a lot. This question is a duplicate up to the unexplained n symbol. – Petr Skocik Sep 23 '15 at 11:41
  • 1
    `end_(end_)` should be `end_(end)`. Using same name instead of underscory-warts avoids this problem :) – M.M Sep 23 '15 at 13:49

1 Answers1

0

Perhaps I can see why this symbols appears in nm output, but I can't tell if it should/shouldn't be there and what exactly n means. Maybe if someone is familiar with this, he can post full answer.

If you make objdump -t ./obj.o you can see a symbol table. Except 2 constructors and many other symbols I see

00000000 l       .group 00000000 _ZN10ConstArrayIKcEC5EPS0_S2_

there. The flag is only l which means it is local and not debug, so I see it in nm output as third symbol.

If I do nm -g ./obj.o to see only extern symbols, I see only 2 W constructors and when I do nm -a ./obj.o I see all the symbols and also marked in objdump -x as debug. And I also see there some debug symbols that aren-flagged in nm -a output.

So I don't know what n means, but the third symbol is somehow related to .group section of elf file. Which is responsible for grouping symbols together.

JustAnotherCurious
  • 2,208
  • 15
  • 32