Suppose I have a pseudo-code C, as shown below:
int x = 0;
int y = 0;
int __attribute__ ((noinline)) func1(void)
{
int prev = x; (1)
x |= FLAG; (2)
return prev; (3)
}
int main(void)
{
int tmp;
...
y = 5; (4)
compiler_mem_barrier();
func1();
compiler_mem_barrier();
tmp = y; (5)
...
}
Suppose this is a single-threaded process, so we don’t need to worry about locks. And suppose the code runs on an x86 system. Assume also that the compiler does not perform any reordering.
I understand that x86 systems can only change write / read commands (Reading can be reordered using older writes in different places, but not with older writes to the same place). But I don’t understand if call / ret instructions are considered WRITE / READ instructions. So here are my questions:
x86 "" WRITE? , . , . , , .
"ret" READ ( )?
, "ret" . , (3) (2) ASM ? , "ret" . Intel Manual, "ret" .
(1) (4)? , (1) (4). "" "jmp", ... , , , -, , .
(5) (5)? "ret" READ, , . , , - .
func1(), :
mov %gs:0x24,%eax (1)
orl $0x8,%gs:0x24 (2)
retq (3)
, . !