Results 1 to 5 of 5

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

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default can use -ffunction-sections -Wl,--gc-sections to reduce size of static-linked Qt app?

    I have been using
    Qt Code:
    1. -fdata-sections -ffunction-sections -Wl,--gc-sections
    To copy to clipboard, switch view to plain text mode 
    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?
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: can use -ffunction-sections -Wl,--gc-sections to reduce size of static-linked Qt

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: can use -ffunction-sections -Wl,--gc-sections to reduce size of static-linked Qt

    Quote Originally Posted by wysota View Post
    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.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can use -ffunction-sections -Wl,--gc-sections to reduce size of static-linked Qt

    In the qt.conf file for that specific architecture. The conf files are located in $QTDIR/mkspecs.

    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: can use -ffunction-sections -Wl,--gc-sections to reduce size of static-linked Qt

    Quote Originally Posted by jamadagni View Post
    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.

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 11:12
  2. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 17:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.