Removing RTTI from binaries

Johannes Pfau via D.gnu d.gnu at puremagic.com
Sun Jan 11 08:57:40 PST 2015


Am Sun, 11 Jan 2015 15:15:38 +0000
schrieb "Mike" <none at none.com>:

> On Sunday, 11 January 2015 at 15:02:07 UTC, bearophile wrote:
> > Mike:
> >
> >> I'm building some code that is heavily templated.  Therefore, 
> >> I have many very small classes.
> >
> > This is a non sequitur.
> 
> I believe it is because nearly every one of the instantiated 
> template names is appears in the .rodata section, thus causing 
> the binary's size to inflate.
> 

That's likely used/caused by the TypeInfo.name property.

> >
> >> Most of my code just uses classes as namespaces calling static 
> >> methods and properties.
> >
> > Aren't structs better for that?
> 
> Not in my current design, as I also make use of inheritance.  If 
> you're curious, you can see the code here: 
> https://github.com/JinShil/stm32f42_discovery_demo, specifically 
> the stm32f42 folder.
> 
> Mike
> 

I guess you'd see the same problem with structs.

There's no standard way to avoid TypeInfo right now. -fno-rtti would
disable TypeInfo completely but it's not implemented in upstream GDC.

If you can disable TypeInfo for all classes open gcc/d/d-objfile.cc
search for
"// Put out the TypeInfo"
in ClassDeclaration::toObjFile

and comment out this line:
"type->getTypeInfo (NULL);"


If you only want to disable TypeInfo for some classes that's more
difficult:
https://github.com/D-Programming-microD/GDC/commit/f0614bc9480dacd1ec6bb75277d280afa96e08bb


More information about the D.gnu mailing list