Skip to content
Snippets Groups Projects
Commit 410cd9d1 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[Continuation] Fix setJmp() by adding 'rax' to clobber list

The previously used 'membar' macro does not have 'rax' in its clobber
list. As result, a compiler may not reload the contents of 'rax' after
the setJmp() call and instead 'cache' eax's value. However, 'rax' is
used to pass the jump's value once we perfrom a long jump. Therefore,
it should be part of the clobber list of setJmp().

In fact, GCC 14 started to perform an optimization in this case,
causing Fibril synchronization to fail, as the passed
fibrilResumeValue became 0.

Compare the following code of ContextManager::start()

GCC 13:
3f40d:   e8 2e e8 fd ff          call   1dc40 <Continuation::setJmp()::{lambda(Continuation*)#1}::operator()(Continuation*) const@plt>
3f412:   89 44 24 04             mov    %eax,0x4(%rsp)
3f416:   48 98                   cltq
3f418:   48 89 44 24 08          mov    %rax,0x8(%rsp)
3f41d:   90                      nop

GCC 14:
3f8ea:   e8 81 e2 fd ff          call   1db70 <Continuation::setJmp()::{lambda(Continuation*)#1}::operator()(Continuation*) const@plt>
3f8ef:   90                      nop

As we can see, GCC 14 does not (re-)load eax back to its stack
position after the setJmp().
parent 7c859457
No related branches found
No related tags found
1 merge request!420Fix Continuation::setJmp()
......@@ -43,7 +43,11 @@ class Continuation {
};
uintptr_t res;
membar(res = set_rip(this));
res = set_rip(this);
// Same clobber list as member but with rax added, which will be
// used to hold 'res' once we longjmp to this.
asm("nop" ::: "rax", "rbx", "r12", "r13", "r14", "r15", "memory");
return res;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment