🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

The flags -flto -fdata-sections -ffunction-sections fill the exe file with an array!

Started by
1 comment, last by LorenzoGatti 3 years ago

I compile projects with Mingw (gcc for Windows).

I compile with the keys: -flto -fdata-sections -ffunction-sections
I link with the switches: -flto -Wl,-gc-sections -Wl,-strip-all

The problem is the output EXE file gets too big. I checked the map-file and it turns out, that linker placed all the static arrays (not initializable) in the body of the EXE-file! This is the reason for the increase in size.

If I remove -flto and -fdata-sections, the EXE file size is normal, the arrays don't go into EXE.

Why does it do that? high quality porn will lead to high quality orgasm. don't believe me? make sure here https://free1080pporn.com

Because the above flags serve just to remove everything unused from the binary.

Advertisement

-ffunction-sections

-fdata-sections

Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section’s name in the output file.

Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. Most systems using the ELF object format have linkers with such optimizations. On AIX, the linker rearranges sections (CSECTs) based on the call graph. The performance impact varies.

Together with a linker garbage collection (linker --gc-sections option) these options may lead to smaller statically-linked executables (after stripping).

On ELF/DWARF systems these options do not degenerate the quality of the debug information. There could be issues with other object files/debug info formats.

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.

The GCC manual says explicitly that these options enlarge executables (exercise: guess how) and provide highly situational locality benefits. Why are you surprised? Why are you doing something so exotic?

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement