I understand that name mangling happens. What I don't understand is this:
class MyClass{
public:
int doStuff(int a){
return a+1;
}
};
int main(){
MyClass myclass;
myclass.doStuff(2);
return 0;
}
> g++ -c -O0 blah.cpp && objdump -h blah.o
blah.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .group 00000008 0000000000000000 0000000000000000 00000040 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
1 .text 00000043 0000000000000000 0000000000000000 00000048 2**0
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
2 .data 00000000 0000000000000000 0000000000000000 0000008b 2**0
CONTENTS, ALLOC, LOAD, DATA
3 .bss 00000000 0000000000000000 0000000000000000 0000008b 2**0
ALLOC
4 .text._ZN7MyClass7doStuffEi 00000013 0000000000000000 0000000000000000 0000008c 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
5 .comment 00000036 0000000000000000 0000000000000000 0000009f 2**0
CONTENTS, READONLY
6 .note.GNU-stack 00000000 0000000000000000 0000000000000000 000000d5 2**0
CONTENTS, READONLY
7 .eh_frame 00000058 0000000000000000 0000000000000000 000000d8 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
Why is MyClass.doStuff in its own section, the section name being the mangled symbol for that member function?
I think this is not necessary for the linking to work, since it is the symbols that match when linking, not sections. ie. if everything was in .text it should work.
Is there a way to make this not happen?