frankengcc
Chris Waterson (waterson@netscape.com)
As part of the
overall effort
to reduce the runtime footprint of Mozilla-the-browser and the Gecko
layout engine, we've done some investigation into the tools that we
use to build the Mozilla and its components. We identified two
problems early on with the way gcc handles large C++
projects:
-
gccgenerates vacuous vtables for classes that have only pure virtual methods. Mozilla has a lot of these (one for eachnsIinterface), as that's how XPCOM works. See this article for details. -
gccdoesn't do a good job handling declarations like:class nsIFoo { public: static const nsIID& GetIID() { static const nsIID iid = { /* IID data here */ }; return iid; } };Specifically, gcc seems to generate aniidfor each interface in each translation unit, and these are not combined during the link phase. Again, we see a lot of these in Mozilla, as the staticGetIID()method is used bynsCOMPtr's automatic interface-safety mechanisms. See this article for more details.
So netscape hired a contractor,
Ron Guilmette (rfg@monkeys.com)
to help us figure out what to do. He ended up producing a set of
patches
that can be applied against gcc-2.95.2. These patches
cause gcc to (1) not emit a vtable for a class that has
only pure virtual methods, and (2) place the iid symbols
in a special link-once section that allows ld to
combine redundant copies.
These two changes reduce the runtime static data size by about 36%,
for an overall reduction in initial runtime footprint of about 6%. A
detailed breakdown of the savings (as measured using the
size command) is available
here.