This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 2/4] Fix internal_clone for x32
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org, konstantin dot s dot serebryany at gmail dot com
- Date: Tue, 5 Nov 2013 05:57:49 -0800
- Subject: [PATCH 2/4] Fix internal_clone for x32
- Authentication-results: sourceware.org; auth=none
We need to allcate 2 64-bit integers to restore fn and arg with pop,
which only pop 64-bit integer into 64-bit register. Also pointers
are 32-bit for x32. This patch properly loads r8/r10 fpr syscall.
Please install it.
Thanks.
H.J.
---
libsanitizer/ChangeLog.x32 | 6 ++++++
libsanitizer/sanitizer_common/sanitizer_linux.cc | 16 ++++++++--------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/libsanitizer/ChangeLog.x32 b/libsanitizer/ChangeLog.x32
index 7b54005..40b185d 100644
--- a/libsanitizer/ChangeLog.x32
+++ b/libsanitizer/ChangeLog.x32
@@ -1,5 +1,11 @@
2013-11-05 H.J. Lu <hongjiu.lu@intel.com>
+ * sanitizer_common/sanitizer_linux.cc (internal_clone): Allocate
+ 2 64-bit integers to save and restore fn and arg. Properly load
+ newtls/child_tidptr into r8/r10.
+
+2013-11-05 H.J. Lu <hongjiu.lu@intel.com>
+
* sanitizer_common/sanitizer_linux.cc (internal_mmap): Cast
pointers to uptr for 64-bit syscalls.
(internal_munmap): Likewise.
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cc b/libsanitizer/sanitizer_common/sanitizer_linux.cc
index e48bee5..bb43437 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_linux.cc
@@ -772,9 +772,11 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
if (!fn || !child_stack)
return -EINVAL;
CHECK_EQ(0, (uptr)child_stack % 16);
- child_stack = (char *)child_stack - 2 * sizeof(void *);
- ((void **)child_stack)[0] = (void *)(uptr)fn;
- ((void **)child_stack)[1] = arg;
+ child_stack = (char *)child_stack - 2 * sizeof(unsigned long long);
+ ((unsigned long long *)child_stack)[0] = (uptr)fn;
+ ((unsigned long long *)child_stack)[1] = (uptr)arg;
+ void *r8 __asm__ ("r8") = newtls;
+ int *r10 __asm__ ("r10") = child_tidptr;
__asm__ __volatile__(
/* %rax = syscall(%rax = __NR_clone,
* %rdi = flags,
@@ -783,8 +785,6 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
* %r8 = new_tls,
* %r10 = child_tidptr)
*/
- "movq %6,%%r8\n"
- "movq %7,%%r10\n"
".cfi_endproc\n"
"syscall\n"
@@ -816,9 +816,9 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
"S"(child_stack),
"D"(flags),
"d"(parent_tidptr),
- "r"(newtls),
- "r"(child_tidptr)
- : "rsp", "memory", "r8", "r10", "r11", "rcx");
+ "r"(r8),
+ "r"(r10)
+ : "rsp", "memory", "r11", "rcx");
return res;
}
#endif // defined(__x86_64__)
--
1.8.3.1