Murray's Blog

C++ Code Size

I’d really like some tool (ideally, g++ based) that shows me what parts of compiled/linked code are generated from what parts of C++ source code. For instance, to see whether a particular template is being instantiated for hundreds of different types (fixable via a template specialization) or whether code is being inlined excessively, or whether particular functions are larger than expected.

libgtkmm-2.4 is a bit bigger than I’d like, even stripped, as are the gtkmm examples.

Updates

I forgot to mention that using -g -Os (optimize for size, which disables function-align among other things) has no noticeable effect – it seem to actually make the .so slightly bigger.)

One obvious thing that bothers me: nm shows that stuff in anonymous namespaces are exported. But we put private code in anonymous namespaces to prevent exactly that. I’d prefer to automatically export everything and have a way to exclude some things, rather than automatically not export everything (-fvisibility=hidden)and then explicitly export each thing, hoping I’ve tagged everything.

However, I doubt that exporting/not-exporting would make much difference to the code size. It would still be in the .so because it’s needed for implementation.

More Updates

There’s obviously lots of exerimentation yet to do. The anonymous namespaces really are exported (nm shows them even when using -D. Thanks James). I can hide the standalone functions by using the static keyword, but I don’t think that classes can use the static keyword to specify that they aren’t exported.
The output from nm –demangle -D libgtkmm-2.4.so.1.0.25 (for gtkmm 2.8) is online for anyone interested.

There obviously are thousands of little functions (class methods) in gtkmm, but it doesn’t feel right that the size of the library is comparable to that of the library that it wraps.

Exit mobile version