[PATCH][SH] SH CFI directives patch, revised
Thomas Schwinge
thomas@codesourcery.com
Sat Jun 23 10:16:00 GMT 2012
Hi!
On Mon, 28 May 2012 08:23:34 +0900, Kaz Kojima <kkojima@rr.iij4u.or.jp> wrote:
> Thomas Schwinge <thomas@codesourcery.com> wrote:
> >> 3) The SYSCALL_ERROR_HANDLER macro in
> >> sysdeps/unix/sysv/linux/sh/sysdep.h has been changed to use CFI
> >> directives to mark r12's save/restore. The RTLD_PRIVATE_ERRNO version
> >> is not dealt with, because simply, r12 there is never saved.
> >
> > Hmm, I don't quite understand how that code can get away with not
> > preserving r12 -- Kaz, do you have an explanation? The code in question:
>
> I don't remember any explanation. Maybe just my oversight.
> I agree that r12 should be preserved there.
I found some more places, and now pushed the following as commit
58f902b8d8cd47e8f4f2fcd64721a6289400422e:
* sysdeps/sh/____longjmp_chk.S (CALL_FAIL): Preserve r12 and pr
registers for frame unwinding purposes, add CFI directives.
* sysdeps/unix/sysv/linux/sh/____longjmp_chk.S (CALL_FAIL): Likewise.
* sysdeps/unix/sysv/linux/sh/makecontext.S (.Lexitcode): Likewise
* sysdeps/unix/sysv/linux/sh/sysdep.h (SYSCALL_ERROR_HANDLER):
Likewise.
diff --git a/sysdeps/sh/____longjmp_chk.S b/sysdeps/sh/____longjmp_chk.S
index e8d5f68..b37a948 100644
--- a/sysdeps/sh/____longjmp_chk.S
+++ b/sysdeps/sh/____longjmp_chk.S
@@ -28,9 +28,16 @@ longjmp_msg:
# define CALL_FAIL \
mov.l .Lfail, r1; \
mov.l .Lstr, r4; \
+ mov.l r12, @-r15; \
+ cfi_remember_state; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r12, 0); \
mova .Lgot, r0; \
mov.l .Lgot, r12; \
add r0, r12; \
+ sts.l pr, @-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
bsrf r1; \
add r12, r4; \
/* Unreachable. */ \
@@ -41,11 +48,16 @@ longjmp_msg:
.Lstr: \
.long longjmp_msg@GOTOFF; \
.Lfail: \
- .long __GI___fortify_fail@PLT-(.Lfail0-.);
+ .long __GI___fortify_fail@PLT-(.Lfail0-.); \
+ cfi_restore_state;
#else
# define CALL_FAIL \
mov.l .Lfail, r1; \
mov.l .Lstr, r4; \
+ sts.l pr, @-r15; \
+ cfi_remember_state; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
jsr @r1; \
nop; \
/* Unreachable. */ \
@@ -53,7 +65,8 @@ longjmp_msg:
.Lstr: \
.long longjmp_msg; \
.Lfail: \
- .long __fortify_fail;
+ .long __fortify_fail; \
+ cfi_restore_state;
#endif
#define CHECK_SP(reg) \
diff --git a/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
index bcf828b..d74caa2 100644
--- a/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/sh/____longjmp_chk.S
@@ -32,9 +32,16 @@ longjmp_msg:
# define CALL_FAIL \
mov.l .Lfail, r1; \
mov.l .Lstr, r4; \
+ mov.l r12, @-r15; \
+ cfi_remember_state; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r12, 0); \
mova .Lgot, r0; \
mov.l .Lgot, r12; \
add r0, r12; \
+ sts.l pr, @-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
bsrf r1; \
add r12, r4; \
.Lfail0: \
@@ -45,11 +52,16 @@ longjmp_msg:
.Lstr: \
.long longjmp_msg@GOTOFF; \
.Lfail: \
- .long __GI___fortify_fail@PLT-(.Lfail0-.);
+ .long __GI___fortify_fail@PLT-(.Lfail0-.); \
+ cfi_restore_state;
#else
# define CALL_FAIL \
mov.l .Lfail, r1; \
mov.l .Lstr, r4; \
+ sts.l pr, @-r15; \
+ cfi_remember_state; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
jsr @r1; \
nop; \
/* Unreachable. */ \
@@ -57,7 +69,8 @@ longjmp_msg:
.Lstr: \
.long longjmp_msg; \
.Lfail: \
- .long __fortify_fail;
+ .long __fortify_fail; \
+ cfi_restore_state;
#endif
#define CHECK_SP(reg) \
diff --git a/sysdeps/unix/sysv/linux/sh/makecontext.S b/sysdeps/unix/sysv/linux/sh/makecontext.S
index ec9ce91..a04bc9f 100644
--- a/sysdeps/unix/sysv/linux/sh/makecontext.S
+++ b/sysdeps/unix/sysv/linux/sh/makecontext.S
@@ -97,8 +97,12 @@ ENTRY(__makecontext)
cfi_endproc
.align 5
+ cfi_startproc
.Lexitcode:
#ifdef PIC
+ mov.l r12, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (r12, 0)
mova .Lgot, r0
mov.l .Lgot, r12
add r0, r12
@@ -107,6 +111,9 @@ ENTRY(__makecontext)
bt/s 2f
mov r8, r4 /* r4 <- ucb->uc_link */
mov.l .Lsetcontext, r1
+ sts.l pr, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (pr, 0)
#ifdef PIC
bsrf r1
.LPCS0:
@@ -115,6 +122,10 @@ ENTRY(__makecontext)
jsr @r1
nop
#endif
+ /* Restore to keep CFI/CFA balanced. */
+ lds.l @r15+, pr
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (pr)
/* If this returns (which can happen if the syscall fails) we'll exit
the program with the return error value (-1). */
@@ -143,7 +154,6 @@ ENTRY(__makecontext)
.Lexit:
.long HIDDEN_JUMPTARGET(exit)
#endif
- cfi_startproc
PSEUDO_END(__makecontext)
weak_alias (__makecontext, makecontext)
diff --git a/sysdeps/unix/sysv/linux/sh/sysdep.h b/sysdeps/unix/sysv/linux/sh/sysdep.h
index 5215a84..ce72c66 100644
--- a/sysdeps/unix/sysv/linux/sh/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sh/sysdep.h
@@ -100,11 +99,15 @@
# if RTLD_PRIVATE_ERRNO
# define SYSCALL_ERROR_HANDLER \
neg r0,r1; \
+ mov r12,r2; \
+ cfi_register (r12, r2); \
mov.l 0f,r12; \
mova 0f,r0; \
add r0,r12; \
mov.l 1f,r0; \
mov.l r1,@(r0,r12); \
+ mov r2,r12; \
+ cfi_restore (r12); \
bra .Lpseudo_end; \
mov _IMM1,r0; \
.align 2; \
@@ -121,6 +124,7 @@
# define SYSCALL_ERROR_HANDLER \
neg r0,r1; \
mov r12,r2; \
+ cfi_register (r12, r2); \
mov.l 0f,r12; \
mova 0f,r0; \
add r0,r12; \
@@ -128,6 +132,7 @@
stc gbr, r4; \
mov.l @(r0,r12),r0; \
mov r2,r12; \
+ cfi_restore (r12); \
add r4,r0; \
mov.l r1,@r0; \
bra .Lpseudo_end; \
@@ -140,12 +145,14 @@
# define SYSCALL_ERROR_HANDLER \
neg r0,r1; \
mov r12,r2; \
+ cfi_register (r12, r2); \
mov.l 0f,r12; \
mova 0f,r0; \
add r0,r12; \
mov.l 1f,r0; \
mov.l @(r0,r12),r0; \
mov r2,r12; \
+ cfi_restore (r12); \
mov.l r1,@r0; \
bra .Lpseudo_end; \
mov _IMM1,r0; \
Grüße,
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120623/a0078051/attachment.sig>
More information about the Libc-alpha
mailing list