Base of a Class

Jason Gunthorpe
Sun Oct 19 00:18:00 GMT 1997


I was just fiddling around with g++ ( when I noticed it wasn't
emitting inlined functions along with the class base member. So I made a
quick test program and ran it through my copy of eg++ (970904 snapshot)
and it did the same thing.

Tacked onto this message are the 3 files I used to demonstrate this.
  > eg++ -c t?.cc
  > nm --demangle --print-file-name t?.o
t1.o:00000000 W Test::~Test(void)
t1.o:00000000 T Test::Test(void)
t1.o:         U __builtin_delete
t1.o:00000004 C __eh_cleanup
t1.o:00000001 C __eh_in_catch
t1.o:00000004 C __eh_pc
t1.o:00000004 C __eh_type
t1.o:00000004 C __eh_value
t1.o:         U __rtti_user
t1.o:00000000 W Test type_info function
t1.o:00000008 C Test type_info node
t1.o:00000000 W Test virtual table
t1.o:00000000 t gcc2_compiled.
t2.o:00000000 T AFunc(void)
t2.o:00000000 W Test::TestFunc(void)
t2.o:00000000 W Test::TestInline(void)
t2.o:00000000 W Test::~Test(void)
t2.o:         U Test::Test(void)
t2.o:         U __builtin_delete
t2.o:00000004 C __eh_cleanup
t2.o:00000001 C __eh_in_catch
t2.o:00000004 C __eh_pc
t2.o:00000004 C __eh_type
t2.o:00000004 C __eh_value
t2.o:         U __get_dynamic_handler_chain
t2.o:         U __rtti_user
t2.o:00000000 W Test type_info function
t2.o:00000008 C Test type_info node
t2.o:00000000 W Test virtual table
t2.o:00000000 t gcc2_compiled.    

As you can see a significant portion of the class membership has been
emitted in both modules. This I found highly surprising (esp considering
what the info files in 2.7 said about template instantiations). 

One compiler I have used the past (High C++) had the notion of the 'base'
of a class. It was defined to be the file that contained the first non-
static non-inline member function. In my example this would be
Test::Test(). What the compiler would do is emit all the inline functions,
vtables and RTTI data into the compilation unit that contained this
function. All other units would not emit the object and simply reference
them as normal extern items.

Presumably this saves compilation time and code size on disk. I haven't
looked at what effect this has on shared libraries, but I suspect it would
increase the size of both the library and client?

Would a feature like this be easy to add and desirable for eg++? I checked
the web archives and I haven't seen any discussion of this topic.

class Test

   inline bool TestInline() {return true;};
   bool TestFunc() {return true;};

   virtual ~Test() {};
#include "t.h"

#include "t.h"

void AFunc()
   Test T;

More information about the Gcc-bugs mailing list