PDA

View Full Version : can use -ffunction-sections -Wl,--gc-sections to reduce size of static-linked Qt app?



jamadagni
19th April 2007, 02:31
I have been using

-fdata-sections -ffunction-sections -Wl,--gc-sections
as options to gcc when compiling a certain library that I statically link to my app, so that the individual functions within object files are treated as separate linkable objects which further reduces my target executable size. I needed to use this facility of gcc since this library is not cleanly == modularly written so that potentially independent units are placed in separate source files.

I wonder if it would be possible to use these options when building the static Qt 4 libraries so that any functions I don't use don't end up wasting space in my executable. If yes, then where can I specify these options?

wysota
19th April 2007, 10:02
From what I know this option wouldn't make sense for static libraries. Static libs are just an archive of functions and only the ones really used will be linked. The problem with Qt is that "many things depend on many other things", so it's really really hard to strip away something that is implemented in the same module as something else.

jamadagni
19th April 2007, 11:38
From what I know this option wouldn't make sense for static libraries.
Negative. See below.

Static libs are just an archive of functions and only the ones really used will be linked.
I am aware of that. If libfoo.a contains goo.o and boo.o and the program doo which links to libfoo.a uses only what goo.o provides, then boo.o is not linked into doo.

But if there are many functions inside goo.o and the target doo uses only a few of them, the linker would add into the target even the unused functions. This is what I am trying to avoid. With the options I'm talking about, it won't add in the unused functions. man:gcc and man:ld confirm this statement.


The problem with Qt is that "many things depend on many other things", so it's really really hard to strip away something that is implemented in the same module as something else.
Hey, I let ld worry about that. I'm not going to tell it - strip this out, don't strip that out.

Now my question remains: where can I give such options to the compiler when using qmake.

marcel
19th April 2007, 11:45
In the qt.conf file for that specific architecture. The conf files are located in $QTDIR/mkspecs.

Regards

wysota
19th April 2007, 13:17
Negative. See below.

I am aware of that. If libfoo.a contains goo.o and boo.o and the program doo which links to libfoo.a uses only what goo.o provides, then boo.o is not linked into doo.

But if there are many functions inside goo.o and the target doo uses only a few of them, the linker would add into the target even the unused functions. This is what I am trying to avoid. With the options I'm talking about, it won't add in the unused functions. man:gcc and man:ld confirm this statement.
Functions is one thing, methods is another. Is it able to strip methods from a class? If so, then fine.


Now my question remains: where can I give such options to the compiler when using qmake.

QMAKE_CXXFLAGS or QMAKE_LFLAGS depending on what component should receive them.