0

Consider the following code:

class base {
 public:
   base() = default;
   virtual int foo() { return 0; }
};

class derived : public base {
 public:
   derived() = default;
   virtual int foo() { return 1;}
};

Compiling this with Clang 3.3 I get the following output for the vtable:

__ZTV7derived:
.long   0        <--- what is this?
.long   __ZTI7derived
.long   __ZN7derived3fooEv

If I add the switch -fno-rtti I get this:

__ZTV7derived:
.long   0        <--- what is this?
.long   0        <--- type info removed by -fno-rtti
.long   __ZN7derived3fooEv

Which makes sense since the TypeInfo is now invalid, but what is the first .long 0 referring to? Also, why doesn't -fno-rtti remove the type info altogether rather than just zero-ing it? I'm considering writing a pass to do this manually, but I'd like to know the implications of it first (I'm squeezing bytes out of an embedded platform)

Sam Cristall
  • 4,328
  • 17
  • 29
  • @MM. Thanks, that looks like that's it! Though I'm still curious what happens if I remove this info manually (since -fno-rtti doesn't completely remove it) – Sam Cristall Nov 20 '13 at 16:42
  • 1
    The second-entry is zeroed-out for binary compatibility. You could link with a rtti-enabled library from a no-rtti program for example. – François Moisan Nov 20 '13 at 16:43
  • @FrançoisMoisan I see, that makes sense. If I'm doing this as a "whole program" optimization, I'd be safe then? I already strictly forbid `dynamic_cast` and multiple inheritance. – Sam Cristall Nov 20 '13 at 16:46
  • @SamCristall. Can't say anything further than that. Not sure what the compiler does with the rest of that information. Does it assume that same offset for virtual function lookup ? If it does you would run into a whole new bunch of problems. You'd need intricate knowledge of what the compiler does. – François Moisan Nov 20 '13 at 16:51
  • @FrançoisMoisan I'll have to dig into it to check on that, I was mostly just concerned with the C++ language implications of cutting this info out. Thanks for your help! – Sam Cristall Nov 20 '13 at 16:57

0 Answers0