Query on -ffunction-section & -fdata-sections options of gcc

后端 未结 5 1361
陌清茗
陌清茗 2020-12-01 07:50

The below mentioned in the GCC Page for the function sections and data sections options:

-ffunction-sections
-fdata-sections
5条回答
  •  天涯浪人
    2020-12-01 08:00

    You can use -ffunction-sections and -fdata-sections on static libraries, which will increase the size of the static library, as each function and global data variable will be put in a separate section.

    And then use -Wl,--gc-sections on the program linking with this static library, which will remove unused sections.

    Thus, the final binary will be smaller than without those flags.

    Be careful though, as -Wl,--gc-sections can break things.

提交回复
热议问题