Removing RTTI from binaries

Mike via D.gnu d.gnu at puremagic.com
Sun Jan 11 06:55:53 PST 2015


I'm building some code that is heavily templated.  Therefore, I 
have many very small classes.  I was surprised to see my binaries 
growing very large, disproportionately to the amount of code I 
was adding.  I inspected the binaries with objdump and found 
contents of the .rodata section like the following:

  801fa00 6572616c 2e526567 69737465 72212830  eral.Register!(0
  801fa10 2c206361 73742841 63636573 73293729  , cast(Access)7)
  801fa20 2e526567 69737465 722e4269 74212831  .Register.Bit!(1
  801fa30 312c2063 61737428 4d757461 62696c69  1, cast(Mutabili
  801fa40 74792932 292e4269 74000000 6d6d696f  ty)2).Bit...mmio
  801fa50 2e506572 69706865 72616c21 28414842  .Peripheral!(AHB
  801fa60 312c2031 35333630 292e5065 72697068  1, 15360).Periph
  801fa70 6572616c 2e526567 69737465 72212830  eral.Register!(0
  801fa80 2c206361 73742841 63636573 73293729  , cast(Access)7)
  801fa90 2e526567 69737465 722e4269 74212831  .Register.Bit!(1
  801faa0 322c2063 61737428 4d757461 62696c69  2, cast(Mutabili
  801fab0 74792930 292e4269 74000000 6275732e  ty)0).Bit...bus.
  801fac0 41504232 00000000 6275732e 41504231  APB2....bus.APB1
  801fad0 00000000 6275732e 41484233 00000000  ....bus.AHB3....
  801fae0 6275732e 41484232 00000000 6275732e  bus.AHB2....bus.
  801faf0 41484231 00000000 6275732e 436f7265  AHB1....bus.Core
  801fb00 50657269 70686572 616c7300 54797065  Peripherals.Type
  801fb10 496e666f 5f690000 54797065 496e666f  Info_i..TypeInfo
  801fb20 5f456e75 6d000000 54797065 496e666f  _Enum...TypeInfo
  801fb30 5f417272 61790000 54797065 496e666f  _Array..TypeInfo

Most of my code just uses classes as namespaces calling static 
methods and properties.  The amount of code in my .text segment 
is only a few hundred bytes, but the .rodata section is several 
thousand bytes.

I'm guessing this is RTTI.  Is there any way, either through 
linker scripting, or the compiler to keep this stuff out of my 
binary?

Thanks,
Mike

using GDC 4.9 arm-none-eabi cross-compiler.

compiler flags:
arm-none-eabi-gdc -O3 -nophoboslib -nostdinc -nodefaultlibs 
-nostdlib -fno-emit-moduleinfo -ffunction-sections 
-fdata-sections -Wl,-Tsource/linker/linker.ld -Wl,--gc-sections


More information about the D.gnu mailing list