How does the Linux C ++ compiler (and linker) decide where to put typeinfo?

I have a class defined in one h file and implemented in cpp, which is part of one lib (we will call it libdef).

I have two other libraries that have cpp files that include this h file. One of them makes dynamic_cast () for this class (we will call it libdyn), and the other makes a new one for this class (we will call it libnew).

It seems that in one of these libs there is typeinfo for the type, but not in the other:

user@machine> ld --cref libdef.so | grep -E "typeinfo for MyClass"
ld: warning: cannot find entry symbol _start; not setting start address
typeinfo for MyClass libdef.so

user@machine> ld --cref libnew.so | grep -E "typeinfo for MyClass"
ld: warning: cannot find entry symbol _start; not setting start address
typeinfo for MyClass libdef.so

user@machine> ld --cref libdyn.so | grep -E "typeinfo for MyClass"
ld: warning: cannot find entry symbol _start; not setting start address
typeinfo for MyClass libdyn.so

As you can see how libdef and libnew use typeinfo from libdef, but libdyn uses its own typeinfo. Why is this? How does the compiler / linker decide whether to put the info type in one library or reference it in another?

, libnew libdyn -llibdef.

user@machine> icpc -V
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.0.0.084 Build 20101006
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

user@machine> ld -V
GNU ld version 2.17.50.0.6-14.el5 20061020
Supported emulations:
 elf_x86_64
 elf_i386
 i386linux

, , , cpp lib "" .

, info:

class SomeClass { public: SomeClass(); virtual void func(); };

info :

class SomeClass { public: SomeClass() {} virtual void func() {} };

, info .

+3
4

g++, , info , . libdef , vtable . libdyn , - dynamic_cast. libnew , , , ( ). , , ; ( , , , ).

, . ( dlopen RTLD_LOCAL; , dynamic_cast, , , .so .)

+3

, ++. - , g++.

, , g++ vtable type_info , .

+2

, .

( ), virtual table type info, , , info, . , typeinfo so, .

0
source

I don’t know the implementation details of your compiler and linker, but maybe it’s smart enough not to include the type info where it is not needed?

0
source

All Articles