Background: The compiler may insert padding into a struct to make it's members align better. This will result in the sizeof the struct being larger than the sum of the sizes of it's members. Reordering the members of the structure so they pack better can remove the need for the compiler to pad in this manner and make the struct smaller saving memory. I need to get those memory savings.
The fallback option is to check every struct by hand. I'm looking for an automated approach that can cut down the effort.
Even if it only reduces the number of structs to be checked by hand that would help.
So for example a process/tool/etc that lists all the structs that are bigger than the sum of the sizes of their members, while not perfect would still be helpful as it would limit the ones that need to be manually checked.
Does anyone know of any tools that can do this or can anyone suggest any approaches that might help.
p.s. I need to do this on an embedded C codebase containing over 1 million lines of code.
pahole is a utility written for this specific purpose. It'll analyse your compiled object files (compiled with debugging enabled), and show you the structure holes.
gcc's -Wpadded warning option can be used to tell you when a structure is being padded. This won't tell you when the structure can be made smaller, but it can help reduce the work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With