TheAssemblyArmada / Vanilla-Conquer

Vanilla Conquer provides clean, cross-platform builds of the C&C Remastered Collection and the standalone legacy games.
Other
358 stars 54 forks source link

Add check whether compiler supports -fdata-sections/-ffunction-sections #979

Closed th-otto closed 5 months ago

OmniBlade commented 8 months ago

@hifi could you comment on if we still need these compiler options at all?

th-otto commented 8 months ago

It would be an optimization to reduce the executable size, but imho only makes sense when used in conjunction with --gc-sections when linking. For MiNT (where all libraries are statically linked) that makes a difference of ~1K

hifi commented 8 months ago

I think those weren't for optimizing but to allow calls to non-existent functions that were optimized out later - this was when we were working on the early version of the code. We probably don't want those if the code compiles without on the CI.

giulianobelinassi commented 6 months ago

Please remove those flags. According to GCC documentation:

Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker create larger object and executable files and are also slower. These options affect code generation. They prevent optimizations by the compiler and assembler using relative locations inside a translation unit since the locations are unknown until link time. An example of such an optimization is relaxing calls to short call instructions. 

hence this is generally a bad idea. If we want to remove dead global functions we should use LTO instead.

th-otto commented 6 months ago

It makes a difference of ~100k of the executable size in my case. LTO does not help, it does not remove unused functions, and it can't be used with static libraries, since they may be compiled by a different compiler version.

But i have no problem cancelling this PR, i can arrange also to add those flags in my build script.

giulianobelinassi commented 6 months ago

It makes a difference of ~100k of the executable size in my case. LTO does not help, it does not remove unused functions, and it can't be used with static libraries, since they may be compiled by a different compiler version.

But i have no problem cancelling this PR, i can arrange also to add those flags in my build script.

interesting. Passing -fwhole-program helps?

Also, can you compare the symbols with and without fdata-sections ffunction-sections so we have a list of funcions that are removed during the link process?

th-otto commented 6 months ago

A log file of the linker about the discarded sections is attached.

discarded.txt.gz

giulianobelinassi commented 6 months ago

I am approving this since there is no other way in the GNU toolchain to remove those symbols without resorting to LTO, which currently breaks the game.

OmniBlade commented 5 months ago

I'll merge this as is and maybe look at if the game still compiles without those on linux with GCC.