This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] [PATCH] Support explicit_bzero, memset_s, memzero_explicit, or similar.


On 12/15/2014 11:26 PM, Rich Felker wrote:
> I don't think the implementation as written is valid -- at least, not
> if you allow LTO. The compiler barrier does not prevent the memset
> from being optimized out unless the address of the buffer being memset
> has been leaked to code the compiler cannot see. As long as it sees
> that the asm has no way of observing the output of the memset, it can
> optimize out the memset. Simply making the memset buffer visible to
> the asm by passing its address (or better yet, it as a memory object)
> in an asm constraint would probably fix this, but I'd like to have
> someone from the GCC side confirm this.

I believe a simple memory clobber (without even passing the buffer address)
should be sufficient.  The memory clobber is a very large hammer, indicating
that *all* memory is both read and written.  Thus the memset cannot be dead,
because its results may be read by the asm.


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]