Does optimizing for size with
gcc -Os only reduce the binary size of a program, or does it reduce its runtime memory usage as well? I know what exactly the results are depend on the specific code, but in general is the result a lower memory usage?
Actually, according to some sources like gentoo-wiki, the
-Os flag can have more benefits than just reduced binary footprint. But extensive usage of it can cause problems. The actual benefits can be seen for large programs, but as the flag can trigger some bugs, one must be careful not to use it with unstable code. So, unfortunately, this means that really large pieces of software are more likely to expose bugs (by pure probability: more code => higher risk of bugs exposure). Many large applications filter this flag out at build-time to prevent such bugs from being exposed.
Also keep in mind that
-Os only can make an application faster - this is not a rule. What is certain about it is that the compiler will try to make the program smaller.