This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[RFC] Add asm constraint modifier to mark strict memory accesses
- From: Yury Gribov <y dot gribov at samsung dot com>
- To: gcc <gcc at gcc dot gnu dot org>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Konstantin Serebryany <konstantin dot s dot serebryany at gmail dot com>, Dmitry Vyukov <dvyukov at google dot com>, Marat Zakirov <m dot zakirov at samsung dot com>
- Date: Thu, 18 Sep 2014 15:09:34 +0400
- Subject: [RFC] Add asm constraint modifier to mark strict memory accesses
- Authentication-results: sourceware.org; auth=none
Hi all,
Current semantics of memory constraints in GCC inline asm (i.e. "m",
"v", etc.) is somewhat loosy in that it tells GCC that asm code _may_
access given amount of bytes but is not guaranteed to do so. This is
(ab)used by e.g. glibc (and also some pieces of kernel):
__STRING_INLINE void *
__rawmemchr (const void *__s, int __c)
{
...
__asm__ __volatile__
("cld\n\t"
"repne; scasb\n\t"
...
"m" ( *(struct { char __x[0xfffffff]; } *)__s)
Imprecise size specification prevents code analysis tools from
understanding semantics of inline asm (without parsing inline asm
instructions which e.g. Asan in Clang tries to do). In particular we
can't automatically instrument inline asm in kernel with Kasan because
we can not determine exact access size (see e.g. discussion in
https://gcc.gnu.org/ml/gcc-patches/2014-05/msg02530.html).
Would it make sense to add another constraint modifier (like "=", "&",
etc.) that would tell compiler/tool that memory access in asm is
_guaranteed_ to have the specified size?
-Y