Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"?
Arsen Arsenović
arsen@aarsen.me
Sun Mar 19 13:18:36 GMT 2023
"3119369616.qq via Gcc" <gcc@gcc.gnu.org> writes:
> To divide functions into sections and then remove unused sections, I must
> provide flags "-fdata-sections" and "-ffunction-sections" in GCC and a flag
> "--gc-sections" in LD. Most of the build systems don't support these flags so
> GCC will generate bigger binaries.
> Is it possible to enable this feature without giving any command line flags manually?
All (at least decent) build systems support passing extra flags to the
compiler and linker (e.g. CXXFLAGS="-ffunction-sections"), or passing a
custom compiler and linker (which can set those flags, something like
CC="gcc -ffunction-sections"). This is how you should be setting such
flags.
If you're interested in DCE and other size-reducing optimizations, you
might also be interested in LTO and -Os.
--
Arsen Arsenović
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 381 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20230319/2291b654/attachment.sig>
More information about the Gcc
mailing list