[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lightning] [BUG] [AMD64 ABI] %r12 not preserved and restored in tra
From: |
Marc Nieper-Wißkirchen |
Subject: |
Re: [Lightning] [BUG] [AMD64 ABI] %r12 not preserved and restored in trampoline function prolog/epilog |
Date: |
Thu, 12 Sep 2019 09:00:36 +0200 |
P.S.: Here is another version of the patch (diff vs the current GIT
version), which makes R12 into the new JIT_V4.
diff --git a/include/lightning/jit_x86.h b/include/lightning/jit_x86.h
index 3350021..a28e375 100644
--- a/include/lightning/jit_x86.h
+++ b/include/lightning/jit_x86.h
@@ -117,21 +117,21 @@ typedef enum {
# define jit_sse_reg_p(reg) ((reg) >= _XMM4 && (reg) <= _XMM0)
# else
# define jit_r(i) (_RAX + (i))
-# define jit_r_num() 4
+# define jit_r_num() 3
# define jit_v(i) (_RBX + (i))
-# define jit_v_num() 4
+# define jit_v_num() 5
# define jit_f(index) (_XMM8 + (index))
# define jit_f_num() 8
# define JIT_R0 _RAX
# define JIT_R1 _R10
# define JIT_R2 _R11
-# define JIT_R3 _R12
- _RAX, _R10, _R11, _R12,
+ _RAX, _R10, _R11,
# define JIT_V0 _RBX
# define JIT_V1 _R13
# define JIT_V2 _R14
# define JIT_V3 _R15
- _RBX, _R13, _R14, _R15,
+# define JIT_V4 _R12
+ _RBX, _R13, _R14, _R15, _R12,
_R9, _R8, _RCX, _RDX, _RSI, _RDI,
_RSP, _RBP,
# define JIT_F0 _XMM8
diff --git a/lib/jit_x86.c b/lib/jit_x86.c
index aae796b..592610f 100644
--- a/lib/jit_x86.c
+++ b/lib/jit_x86.c
@@ -185,11 +185,11 @@ jit_register_t _rvs[] = {
{ rc(arg) | rc(gpr) | rc(rg8) | 0, "%rax" },
{ rc(gpr) | rc(rg8) | 10, "%r10" },
{ rc(gpr) | rc(rg8) | 11, "%r11" },
- { rc(gpr) | rc(rg8) | 12, "%r12" },
{ rc(sav) | rc(rg8) | rc(gpr) | 3, "%rbx" },
{ rc(sav) | rc(rg8) | rc(gpr) | 13, "%r13" },
{ rc(sav) | rc(rg8) | rc(gpr) | 14, "%r14" },
{ rc(sav) | rc(rg8) | rc(gpr) | 15, "%r15" },
+ { rc(sav) | rc(rg8) | rc(gpr) | 12, "%r12" },
{ rc(arg) | rc(rg8) | rc(gpr) | 9, "%r9" },
{ rc(arg) | rc(rg8) | rc(gpr) | 8, "%r8" },
{ rc(arg) | rc(rg8) | rc(gpr) | 1, "%rcx" },
Am Do., 12. Sept. 2019 um 08:38 Uhr schrieb Marc Nieper-Wißkirchen
<address@hidden>:
>
> Hi Paulo,
>
> when creating a function prolog and epilogue for a trampoline function
> as this one
>
> prolog
> frame (...)
> ...
> epilog
>
> GNU lightning saves all callee-save registers in the prolog and
> restores them in the epilog. On the Unix port of x86_64, however, it
> fails to save and restore %r12, which is a callee-saved register.
>
> (This error has led to subtle bugs when I compiled my code with "-O2"
> and gcc began to use %r12 and expected it to be preserved over a call
> into a GNU lightning trampoline.)
>
> The error maybe related to the fact that on GNU lightning, %r12 is
> mapped to JIT_R3, which appears as a caller-save register to the user.
> See also this discussion here:
> https://lists.gnu.org/archive/html/lightning/2017-09/msg00006.html
>
> I'd suggest to apply the patch of this discussion so that %r12 is
> treated like %13, %r14, %15 and will be automatically saved in the
> prolog and restored in the epilog. The side effect will be that JIT_R3
> goes away and JIT_V4 appears.
>
> If you don't want this, the bug has to be fixed differently by
> patching the _prolog and _epilog procedures.
>
> In any case, a fix of this bug is urgent because it is a critical one
> (as non-ABI-conforming code is produced).
>
> Thanks,
>
> Marc