magiclantern_simplified icon indicating copy to clipboard operation
magiclantern_simplified copied to clipboard

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

Open reticulatedpines opened this issue 2 years ago • 3 comments

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.

reticulatedpines avatar Oct 05 '22 18:10 reticulatedpines

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

petabyt avatar Oct 31 '22 17:10 petabyt

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.

reticulatedpines avatar Nov 07 '22 16:11 reticulatedpines

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

petabyt avatar Nov 07 '22 17:11 petabyt