Stephane-D / SGDK

SGDK - A free and open development kit for the Sega Mega Drive
https://www.patreon.com/SGDK
MIT License
1.77k stars 189 forks source link

Consider adding `-ffunction-sections` and `-fdata-sections` compiler options #346

Closed howprice closed 2 months ago

howprice commented 3 months ago

These break up each function and data into its own section in the object files, which allows the linker to better remove dead code when the ld --gc-sections option is used.

Adding these flags to DEFAULT_FLAGS_LIB in makelib.gen and linking against the resulting libmd.a reduces final ROM size significantly in my test case, which calls random() and plays XGM2 audio. (This is an assembler project linking against the library, rather than one built using the framework).

Stephane-D commented 2 months ago

I added the flags hoping it will bring any drawback for C projects (I read mitigated opinions about it). I believe LTO was somehow doing the work of eliminating unused functions / data already but it works better with C projects obviously.