This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimising away memset() calls?
- From: Andrew Haley <aph at redhat dot com>
- To: Ángel González <keisial at gmail dot com>, Florian Weimer <fweimer at redhat dot com>
- Cc: Sandy Harris <sandyinchina at gmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Fri, 10 Oct 2014 10:20:03 +0100
- Subject: Re: Optimising away memset() calls?
- Authentication-results: sourceware.org; auth=none
- References: <CACXcFm=c0kf-2M2V_D+L2PdEoD4qcqKNVmPGQkv8FRKEqw3Zmw at mail dot gmail dot com> <543660DA dot 8010706 at redhat dot com> <5436F593 dot 4020001 at gmail dot com>
On 09/10/14 21:52, Ángel González wrote:
> The compiler would need to know that memset_s is special (either
> intrinsically or thorugh eg. function attributes). Either way, IMHO
> an advanced knowledge allowing to optimize it out would be a
> violation of K.3.7.4.1.
It would be a perverse thing to do and goes against intent, but we
again fall into the problem of defining an access. But this is
irrelevant anyway: even if a key is stored in an array X in the source
code and the array X is later wiped with memset_s(), there is
absolutely nothing to force the compiler to use X during the
computation: it may well store the key somewhere else altogether. So,
all we can have here is a best effort. Anyone who wants to be sure
that the key is wiped is going to have to do something machine-
dependent.
Andrew.