use explicit __cp_cancel label in cancellable syscall asm for all archs

previously, only archs that needed to do stack cleanup defined a
__cp_cancel label for acting on cancellation in their syscall asm, and
a default definition was provided by a weak alias to __cancel, the C
function. this resulted in wrong codegen for arm on gcc versions
affected by pr 68178 and possibly similar issues (like pr 66609) on
other archs, and also created an inconsistency where the __cp_begin
and __cp_end labels were treated as const data but __cp_cancel was
treated as a function. this in turn caused incorrect code generation
on archs where function pointers point to function descriptors rather
than code (for now, only sh/fdpic).
This commit is contained in:
Rich Felker
2015-11-02 16:16:00 -05:00
parent cb1bf2f321
commit 36e8b6a28b
8 changed files with 32 additions and 28 deletions

View File

@ -17,7 +17,7 @@
__syscall_cp_asm: __syscall_cp_asm:
__cp_begin: __cp_begin:
ldr w0,[x0] ldr w0,[x0]
cbnz w0,1f cbnz w0,__cp_cancel
mov x8,x1 mov x8,x1
mov x0,x2 mov x0,x2
mov x1,x3 mov x1,x3
@ -28,6 +28,5 @@ __cp_begin:
svc 0 svc 0
__cp_end: __cp_end:
ret ret
__cp_cancel:
// cbnz might not be able to jump far enough b __cancel
1: b __cancel

View File

@ -11,7 +11,7 @@
__syscall_cp_asm: __syscall_cp_asm:
__cp_begin: __cp_begin:
lwi r5, r5, 0 lwi r5, r5, 0
bnei r5, __cancel bnei r5, __cp_cancel
addi r12, r6, 0 addi r12, r6, 0
add r5, r7, r0 add r5, r7, r0
add r6, r8, r0 add r6, r8, r0
@ -23,3 +23,5 @@ __cp_begin:
__cp_end: __cp_end:
rtsd r15, 8 rtsd r15, 8
nop nop
__cp_cancel:
bri __cancel

View File

@ -12,7 +12,7 @@ __syscall_cp_asm:
__cp_begin: __cp_begin:
l.lwz r3, 0(r3) l.lwz r3, 0(r3)
l.sfeqi r3, 0 l.sfeqi r3, 0
l.bnf __cancel l.bnf __cp_cancel
l.ori r11, r4, 0 l.ori r11, r4, 0
l.ori r3, r5, 0 l.ori r3, r5, 0
l.ori r4, r6, 0 l.ori r4, r6, 0
@ -24,3 +24,6 @@ __cp_begin:
__cp_end: __cp_end:
l.jr r9 l.jr r9
l.nop l.nop
__cp_cancel:
l.j __cancel
l.nop

View File

@ -38,7 +38,7 @@ __cp_begin:
cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7. cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7.
beq+ cr7, 1f #jump to label 1 if r0 was 0 beq+ cr7, 1f #jump to label 1 if r0 was 0
b __cancel #else call cancel b __cp_cancel #else call cancel
1: 1:
#ok, the cancel flag was not set #ok, the cancel flag was not set
# syscall: number goes to r0, the rest 3-8 # syscall: number goes to r0, the rest 3-8
@ -55,3 +55,5 @@ __cp_end:
#else negate result. #else negate result.
neg 3, 3 neg 3, 3
blr blr
__cp_cancel:
b __cancel

View File

@ -7,7 +7,7 @@
#ifdef SHARED #ifdef SHARED
__attribute__((__visibility__("hidden"))) __attribute__((__visibility__("hidden")))
#endif #endif
long __cancel(), __cp_cancel(), __syscall_cp_asm(), __syscall_cp_c(); long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
long __cancel() long __cancel()
{ {
@ -18,12 +18,6 @@ long __cancel()
return -ECANCELED; return -ECANCELED;
} }
/* If __syscall_cp_asm has adjusted the stack pointer, it must provide a
* definition of __cp_cancel to undo those adjustments and call __cancel.
* Otherwise, __cancel provides a definition for __cp_cancel. */
weak_alias(__cancel, __cp_cancel);
long __syscall_cp_asm(volatile void *, syscall_arg_t, long __syscall_cp_asm(volatile void *, syscall_arg_t,
syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
syscall_arg_t, syscall_arg_t, syscall_arg_t); syscall_arg_t, syscall_arg_t, syscall_arg_t);
@ -56,7 +50,7 @@ static void _sigaddset(sigset_t *set, int sig)
#ifdef SHARED #ifdef SHARED
__attribute__((__visibility__("hidden"))) __attribute__((__visibility__("hidden")))
#endif #endif
extern const char __cp_begin[1], __cp_end[1]; extern const char __cp_begin[1], __cp_end[1], __cp_cancel[1];
static void cancel_handler(int sig, siginfo_t *si, void *ctx) static void cancel_handler(int sig, siginfo_t *si, void *ctx)
{ {

View File

@ -14,17 +14,8 @@ __syscall_cp_asm:
__cp_begin: __cp_begin:
mov.l @r4, r4 mov.l @r4, r4
tst r4, r4 tst r4, r4
bt 2f bf __cp_cancel
mov r5, r3
mov.l L1, r0
braf r0
nop
1:
.align 2
L1: .long __cancel@PLT-(1b-.)
2: mov r5, r3
mov r6, r4 mov r6, r4
mov r7, r5 mov r7, r5
mov.l @r15, r6 mov.l @r15, r6
@ -43,3 +34,12 @@ __cp_end:
rts rts
nop nop
__cp_cancel:
mov.l 2f, r0
braf r0
nop
1:
.align 2
2: .long __cancel@PCREL-(1b-.)

View File

@ -14,7 +14,7 @@ __syscall_cp_internal:
__cp_begin: __cp_begin:
mov (%rdi),%eax mov (%rdi),%eax
test %eax,%eax test %eax,%eax
jnz __cancel jnz __cp_cancel
mov %rdi,%r11 mov %rdi,%r11
mov %rsi,%rax mov %rsi,%rax
mov %rdx,%rdi mov %rdx,%rdi
@ -27,3 +27,5 @@ __cp_begin:
syscall syscall
__cp_end: __cp_end:
ret ret
__cp_cancel:
jmp __cancel

View File

@ -14,7 +14,7 @@ __syscall_cp_asm:
__cp_begin: __cp_begin:
mov (%rdi),%eax mov (%rdi),%eax
test %eax,%eax test %eax,%eax
jnz __cancel jnz __cp_cancel
mov %rdi,%r11 mov %rdi,%r11
mov %rsi,%rax mov %rsi,%rax
mov %rdx,%rdi mov %rdx,%rdi
@ -27,3 +27,5 @@ __cp_begin:
syscall syscall
__cp_end: __cp_end:
ret ret
__cp_cancel:
jmp __cancel