www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - rtInfo issue

reply Benjamin Thaut <code benjamin-thaut.de> writes:
I'm currently using the rtInfo template inside object.d to generate RTTI 
information for my own little rtti system. It is working really well so 
far, the only issue I found is as follows:

If a POD struct (which does not contain any reference types, pointers, 
arrays etc) is placed in a library. And that library is then linked 
against a executable, the rtInfo of the POD struct will be lost. It will 
be generated by the compiler when compiling the library, but for some 
reason it is gone after the final binary is compiled and linked. But as 
soon as I add a void* pointer to that struct everythings works fine.

Any idea what could be happening there and how to fix it? If the linker 
stripts the rtInfo out, why does adding a void* make a difference?

The source can be found at:

https://github.com/Ingrater/druntime/blob/master/src/rtti.d
https://github.com/Ingrater/druntime/blob/master/src/object.di

Kind Regards
Benjamin Thaut
Dec 09 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/9/2012 11:36 AM, Benjamin Thaut wrote:
 If a POD struct (which does not contain any reference types, pointers, arrays
 etc) is placed in a library. And that library is then linked against a
 executable, the rtInfo of the POD struct will be lost. It will be generated by
 the compiler when compiling the library, but for some reason it is gone after
 the final binary is compiled and linked. But as soon as I add a void* pointer
to
 that struct everythings works fine.

 Any idea what could be happening there and how to fix it? If the linker stripts
 the rtInfo out, why does adding a void* make a difference?
Template instances are written to COMDAT sections, which are stripped out if they are not referenced.
Dec 09 2012
next sibling parent reply Benjamin Thaut <code benjamin-thaut.de> writes:
Am 09.12.2012 21:22, schrieb Walter Bright:>
 Template instances are written to COMDAT sections, which are stripped
 out if they are not referenced.
But why does adding a void* pointer make a difference then? By adding a void* pointer to the struct it will still not be referenced Before (broken): struct Pod { float x; } After (working): struct Pod { float x; void* ptr; } Kind Regards Benjamin Thaut
Dec 09 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 12/9/2012 12:28 PM, Benjamin Thaut wrote:
 But why does adding a void* pointer make a difference then? By adding a void*
 pointer to the struct it will still not be referenced

 Before (broken):

 struct Pod { float x; }

 After (working):

 struct Pod { float x; void* ptr; }
I suggest looking at the difference between the object files for the two cases.
Dec 09 2012
prev sibling parent Benjamin Thaut <code benjamin-thaut.de> writes:
Ok I tried to manually reference it, it does not help.

struct Quaternion {
	float x,y,z,angle;
}

class ForceReference
{
   Quaternion q;
}

shared static this()
{
   Quaternion q;
   auto t = typeid(Quaternion);
   auto info = RTInfo!Quaternion;
   printf("%x %x\n", info, t.rtInfo);
}

Although info is not null t.rtInfo is null.

Kind Regards
Benjamin Thaut
Dec 09 2012