reticulatedpines / magiclantern_simplified

A Git based version of Magic Lantern, for those unwilling or unable to work using Mercurial. The vast majority of branches have been removed, with those thought to be important brought in individually and merged.
GNU General Public License v2.0
142 stars 50 forks source link

Find object file external functions that are never called, make them static #72

Open reticulatedpines opened 1 year ago

reticulatedpines commented 1 year ago

Just a guess, but I'm assuming we have a significant number of functions in C files that aren't marked static, when they could be.

Doing so would allow the compiler to better optimise, including removing the code from object files entirely if never called. This might be a useful size reduction in magiclantern.

Should be largely automatable with some combination of objdump and maybe semgrep to find usages.

petabyt commented 1 year ago

Does it use -fdata-sections -ffunction-sections and --gc-sections to remove unused functions?

reticulatedpines commented 1 year ago

No idea, but I'm pretty sure it won't include object code for functions that are provably never called. However, if a function is non-static, because the symbol must be externally visible in object files, that function cannot be removed. The compiler cannot prove it's never called.

petabyt commented 1 year ago

It marks sections, and the linker removes unused ones. So it removes unused functions, variables, etc. Static is a better idea probably.