On Tue, 23 Nov 2010 15:45:18 +0100, walter harms said: > hi all, > as we see this is not a question of c99. > Maybe we can convince the gcc people to make 0 padding default. That will not solve the > problems for other compilers but when they claim "works like gcc" we can press then to > support this also. I can imagine that this will close some other subtle leaks also. Note that zero padding by default has a price - the code has to include zeroing instructions for each structure that needs it. In the case of a function that gets inlined, the zeroing instructions could easily cost almost as much as the actual function. So your code ends up bigger and slower. Let's look at that example again: >>>> if (timeval) { >>>> - rtv.tv_sec = rts.tv_sec; >>>> - rtv.tv_usec = rts.tv_nsec / NSEC_PER_USEC; >>>> + struct timeval rtv = { >>>> + .tv_sec = rts.tv_sec, >>>> + .tv_usec = rts.tv_nsec / NSEC_PER_USEC >>>> + }; >>>> >>>> if (!copy_to_user(p, &rtv, sizeof(rtv))) >>>> return ret; Quick - is the optimizer able to eliminate the zero padding? If so, how does it know that? And if the optimizer *can't* eliminate the zero padding, what does that to do the overall generated code quality (especially on CPUs like the x86 in 32-bit mode, where there's significant register pressure)? You might be able to get them to add an *option* to force zero-padding, but there's no way that's going to become the default.
Attachment:
pgp_YloRfcYjY.pgp
Description: PGP signature