[pypy-dev] PPC stacklet switching code

Vaibhav Sood vaibhav_sood at persistent.com
Wed Oct 14 11:26:29 CEST 2015


Hi,

The stack switching code (switch_xxx_gcc.h) for PPC is missing for stacklets under rpython/translator/c/src/stacklet, I am trying to work on adding that code but I am facing an issue when doing that due to the way PPC assembly works and needed some help/advice

I added the switch_ppc64_gcc.h file for PPC with the slp_switch function similar to the one's in the other files (eg. switch_x86_gcc.h etc) and I run the test cases in tests.c to test the new code but these fail with segfaults. I gdb'd the failures and find that the segfaults are due to PPC assembly using the calling functions stack to store the LR register but the g_save_state/g_restore_state functions in stacklet.c overwriting the stack contents causing the stored value to be destroyed

Specifically,

Running test_new(..) in tests.c calls stacklet_new(..) to create a new stacklet which in turn calls g_initialstub. _stacklet_switchstack is called twice here, first to save the old stack contents using g_initial_save_state in the heap memory and then again in the "if" code to restore the contents to the new stack using g_restore_state. The issue is when running the g_restore_state function, at the start the function prologue code saves the Link Register (LR) in the LR save area in the calling function's (slp_switch calls g_restore_state) stack frame as per PPC function calling conventions. This value is restored back into the LR register at the end by the epilogue code to return back to the calling function slp_switch. However in between the calling function's stack content is overwritten by the g_restore_state code (it memcpy's the stored heap memory data to the stack) causing the saved LR value to be destroyed and thus returning from the g_restore_state function (using blr) causes a segfault

I am not sure how to get around this problem since it is specific to the way PPC assembly works and the same thing is not an issue on other platforms, any help/advice/comments would be a great help

Thanks!
Vaibhav

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20151014/c191a14a/attachment.html>


More information about the pypy-dev mailing list