Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobberedunnecessarily

From: Linus Torvalds
Date: Tue Jul 24 2007 - 15:40:50 EST




On Tue, 24 Jul 2007, Trent Piepho wrote:
>
> Speaking of that, why are all the asm functions in arch/i386/lib/string.c
> defined as having a memory clobber, even those which don't modify memory
> like strcmp, strchr, strlen and so on?

That's because the memory clobber will serialize the inline asm with
anything else that reads or writes memory.

So even if we don't actually change any memory, if we cannot describe what
we *read*, then we need to tell gcc to not re-order us wrt things that
could *write*. And the simplest way to do that is to say that you clobber
memory, even if you don't.

So as a more concrete example: imagine that we're doing a "strlen()" on
some local variable. We need to tell gcc that that variable has to be
updated in memory before it schedules the asm. The memory clobber does
that.

(Yes, the "asm volatile" may do so too, but it's very unclear what the
"volatile" on the asm actually does, so ..)

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/