Make clone() compatible with ARM's Thumb-2 instruction set. Bug reported and
fixed by mkrebs@chromium.org
Review URL: http://codereview.chromium.org/8165010
git-svn-id: http://linux-syscall-support.googlecode.com/svn/trunk/lss@7 829466d3-f3f5-3ae4-62ad-de35cf9bba21
diff --git a/linux_syscall_support.h b/linux_syscall_support.h
index 293fd08..604649e 100644
--- a/linux_syscall_support.h
+++ b/linux_syscall_support.h
@@ -2170,8 +2170,24 @@
/* In the child, now. Call "fn(arg)".
*/
"ldr r0,[sp, #4]\n"
+
+ /* When compiling for Thumb-2 the "MOV LR,PC" here
+ * won't work because it loads PC+4 into LR,
+ * whereas the LDR is a 4-byte instruction.
+ * This results in the child thread always
+ * crashing with an "Illegal Instruction" when it
+ * returned into the middle of the LDR instruction
+ * The instruction sequence used instead was
+ * recommended by
+ * "https://wiki.edubuntu.org/ARM/Thumb2PortingHowto#Quick_Reference".
+ */
+ #ifdef __thumb2__
+ "ldr r7,[sp]\n"
+ "blx r7\n"
+ #else
"mov lr,pc\n"
"ldr pc,[sp]\n"
+ #endif
/* Call _exit(%r0).
*/