From owner-freebsd-amd64@FreeBSD.ORG Sun Oct 7 15:20:12 2012 Return-Path: Delivered-To: amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 064661065672; Sun, 7 Oct 2012 15:20:11 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 145BD8FC12; Sun, 7 Oct 2012 15:20:10 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q97FKHSJ032806; Sun, 7 Oct 2012 18:20:17 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q97FK5Mb005146; Sun, 7 Oct 2012 18:20:05 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q97FK5j7005145; Sun, 7 Oct 2012 18:20:05 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 7 Oct 2012 18:20:05 +0300 From: Konstantin Belousov To: amd64@freebsd.org Message-ID: <20121007152005.GX35915@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+y7rRxfO4bOZsSs1" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: current@freebsd.org Subject: Unwind annotations for the libc and libthr asm X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Oct 2012 15:20:12 -0000 --+y7rRxfO4bOZsSs1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Please find below the patch to add the unwind annotations for the libc and libthr assembler routines on amd64. The change shall have no impact on the execution of the changed code, because no functions there ever generate C++ exception or call a function that could generate exception. The addition of the annotations significantly improves the results of the libunwind test suite on FreeBSD/amd64. We are still not on par with Linux, mainly due to the lack of the unwind annotations for the signal trampolines. Fixing this requires VDSO. The addition of the annotations is rather tedious and unrelieved work, so I am sure that there are left bugs. Bugs would affect both libunwind and gdb, but what I see looks like a step forward anyway. Any comments ? diff --git a/lib/libc/amd64/SYS.h b/lib/libc/amd64/SYS.h index a232383..3101be5 100644 --- a/lib/libc/amd64/SYS.h +++ b/lib/libc/amd64/SYS.h @@ -41,15 +41,25 @@ .set CNAME(x),CNAME(__CONCAT(__sys_,x)); \ .weak CNAME(__CONCAT(_,x)); \ .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ - mov __CONCAT($SYS_,x),%eax; KERNCALL; \ - jb HIDENAME(cerror); ret; \ + mov __CONCAT($SYS_,x),%eax; \ + .cfi_undefined %rax; \ + KERNCALL; \ + jb HIDENAME(cerror); \ + ret; \ END(__CONCAT(__sys_,x)) =20 #define PSEUDO(x) ENTRY(__CONCAT(__sys_,x)); \ .weak CNAME(__CONCAT(_,x)); \ .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ - mov __CONCAT($SYS_,x),%eax; KERNCALL; \ - jb HIDENAME(cerror); ret; \ + mov __CONCAT($SYS_,x),%eax; \ + .cfi_undefined %rax; \ + KERNCALL; \ + jb HIDENAME(cerror); \ + ret; \ END(__CONCAT(__sys_,x)) =20 -#define KERNCALL movq %rcx, %r10; syscall +#define KERNCALL movq %rcx,%r10; \ + .cfi_undefined %r10; \ + .cfi_register %rcx,%r10; \ + syscall; \ + .cfi_undefined %rax,%rdx diff --git a/lib/libc/amd64/gen/_setjmp.S b/lib/libc/amd64/gen/_setjmp.S index 9035632..84cc0c9 100644 --- a/lib/libc/amd64/gen/_setjmp.S +++ b/lib/libc/amd64/gen/_setjmp.S @@ -48,7 +48,9 @@ __FBSDID("$FreeBSD$"); =20 ENTRY(_setjmp) movq %rdi,%rax + .cfi_register %rdi,%rax movq 0(%rsp),%rdx /* retval */ + .cfi_undefined %rdx movq %rdx, 0(%rax) /* 0; retval */ movq %rbx, 8(%rax) /* 1; rbx */ movq %rsp,16(%rax) /* 2; rsp */ @@ -60,6 +62,7 @@ ENTRY(_setjmp) fnstcw 64(%rax) /* 8; fpu cw */ stmxcsr 68(%rax) /* and mxcsr */ xorq %rax,%rax + .cfi_undefined %rax ret END(_setjmp) =20 @@ -67,17 +70,30 @@ END(_setjmp) .set CNAME(_longjmp),CNAME(___longjmp) ENTRY(___longjmp) movq %rdi,%rdx + .cfi_undefined %rdx + .cfi_register %rdi,%rdx /* Restore the mxcsr, but leave exception flags intact. */ stmxcsr -4(%rsp) movl 68(%rdx),%eax + .cfi_undefined %rax andl $0xffffffc0,%eax movl -4(%rsp),%edi + .cfi_undefined %rdi andl $0x3f,%edi xorl %eax,%edi movl %edi,-4(%rsp) ldmxcsr -4(%rsp) movq %rsi,%rax /* retval */ + .cfi_def_cfa %rdx,16 + .cfi_offset %rbx,8 + .cfi_offset %rbp,24 + .cfi_offset %r12,32 + .cfi_offset %r13,40 + .cfi_offset %r14,48 + .cfi_offset %r15,56 movq 0(%rdx),%rcx + .cfi_undefined %rcx + .cfi_return_column %rcx movq 8(%rdx),%rbx movq 16(%rdx),%rsp movq 24(%rdx),%rbp diff --git a/lib/libc/amd64/gen/rfork_thread.S b/lib/libc/amd64/gen/rfork_t= hread.S index 5e764db..9ce0484 100644 --- a/lib/libc/amd64/gen/rfork_thread.S +++ b/lib/libc/amd64/gen/rfork_thread.S @@ -46,7 +46,11 @@ __FBSDID("$FreeBSD$"); =20 ENTRY(rfork_thread) pushq %rbx + .cfi_adjust_cfa_offset 8 + .cfi_offset %rbx,-8 pushq %r12 + .cfi_adjust_cfa_offset 8 + .cfi_offset %r12,-16 movq %rdx, %rbx movq %rcx, %r12 =20 @@ -63,7 +67,11 @@ ENTRY(rfork_thread) cmpl $0, %edx jnz 1f popq %r12 + .cfi_adjust_cfa_offset -8 + .cfi_restore %r12 popq %rbx + .cfi_adjust_cfa_offset -8 + .cfi_restore %rbx ret =20 /* @@ -73,6 +81,7 @@ ENTRY(rfork_thread) */ 1: movq %rsi, %rsp + .cfi_def_cfa_register %rsi movq %r12, %rdi=20 call *%rbx movl %eax, %edi @@ -92,7 +101,11 @@ ENTRY(rfork_thread) */ 2: popq %r12 + .cfi_adjust_cfa_offset -8 + .cfi_restore %r12 popq %rbx + .cfi_adjust_cfa_offset -8 + .cfi_restore %rbx jmp HIDENAME(cerror) END(rfork_thread) =20 diff --git a/lib/libc/amd64/gen/setjmp.S b/lib/libc/amd64/gen/setjmp.S index 47772be..356d34c 100644 --- a/lib/libc/amd64/gen/setjmp.S +++ b/lib/libc/amd64/gen/setjmp.S @@ -50,13 +50,21 @@ __FBSDID("$FreeBSD$"); =20 ENTRY(setjmp) pushq %rdi + .cfi_adjust_cfa_offset 8 movq %rdi,%rcx + .cfi_undefined %rcx + .cfi_register %rdi,%rcx movq $1,%rdi /* SIG_BLOCK */ + .cfi_undefined %rdi movq $0,%rsi /* (sigset_t*)set */ + .cfi_undefined %rsi leaq 72(%rcx),%rdx /* 9,10; (sigset_t*)oset */ + .cfi_undefined %rdx /* stack is 16-byte aligned */ call PIC_PLT(CNAME(_sigprocmask)) popq %rdi + .cfi_adjust_cfa_offset -8 + .cfi_restore %rdi movq %rdi,%rcx movq 0(%rsp),%rdx /* retval */ movq %rdx, 0(%rcx) /* 0; retval */ @@ -77,28 +85,51 @@ END(setjmp) .set CNAME(longjmp),CNAME(__longjmp) ENTRY(__longjmp) pushq %rdi + .cfi_adjust_cfa_offset 8 + .cfi_offset %rdi,-8 pushq %rsi + .cfi_adjust_cfa_offset 8 + .cfi_offset %rsi,-16 movq %rdi,%rdx + .cfi_undefined %rdx + .cfi_register %rdi,%rdx movq $3,%rdi /* SIG_SETMASK */ leaq 72(%rdx),%rsi /* (sigset_t*)set */ movq $0,%rdx /* (sigset_t*)oset */ subq $0x8,%rsp /* make the stack 16-byte aligned */ + .cfi_adjust_cfa_offset 8 call PIC_PLT(CNAME(_sigprocmask)) addq $0x8,%rsp + .cfi_adjust_cfa_offset -8 popq %rsi + .cfi_adjust_cfa_offset -8 + .cfi_restore %rsi popq %rdi /* jmpbuf */ + .cfi_adjust_cfa_offset -8 + .cfi_restore %rdi movq %rdi,%rdx + .cfi_register %rdi,%rdx /* Restore the mxcsr, but leave exception flags intact. */ stmxcsr -4(%rsp) movl 68(%rdx),%eax andl $0xffffffc0,%eax movl -4(%rsp),%edi + .cfi_undefined %rdi andl $0x3f,%edi xorl %eax,%edi movl %edi,-4(%rsp) ldmxcsr -4(%rsp) movq %rsi,%rax /* retval */ + .cfi_def_cfa %rdx,16 + .cfi_offset %rbx,8 + .cfi_offset %rbp,24 + .cfi_offset %r12,32 + .cfi_offset %r13,40 + .cfi_offset %r14,48 + .cfi_offset %r15,56 movq 0(%rdx),%rcx + .cfi_undefined %rcx + .cfi_return_column %rcx movq 8(%rdx),%rbx movq 16(%rdx),%rsp movq 24(%rdx),%rbp diff --git a/lib/libc/amd64/gen/sigsetjmp.S b/lib/libc/amd64/gen/sigsetjmp.S index ef90bc6..c264740 100644 --- a/lib/libc/amd64/gen/sigsetjmp.S +++ b/lib/libc/amd64/gen/sigsetjmp.S @@ -58,14 +58,22 @@ ENTRY(sigsetjmp) testl %esi,%esi jz 2f pushq %rdi + .cfi_adjust_cfa_offset -8 movq %rdi,%rcx + .cfi_undefined %rcx + .cfi_register %rdi,%rcx movq $1,%rdi /* SIG_BLOCK */ movq $0,%rsi /* (sigset_t*)set */ leaq 72(%rcx),%rdx /* 9,10 (sigset_t*)oset */ + .cfi_undefined %rdx /* stack is 16-byte aligned */ call PIC_PLT(CNAME(_sigprocmask)) popq %rdi + .cfi_adjust_cfa_offset 8 + .cfi_restore %rdi 2: movq %rdi,%rcx + .cfi_undefined %rcx + .cfi_register %rdi,%rcx movq 0(%rsp),%rdx /* retval */ movq %rdx, 0(%rcx) /* 0; retval */ movq %rbx, 8(%rcx) /* 1; rbx */ @@ -86,8 +94,14 @@ ENTRY(__siglongjmp) cmpl $0,88(%rdi) jz 2f movq %rdi,%rdx + .cfi_undefined %rdx + .cfi_register %rdi,%rdx pushq %rdi + .cfi_adjust_cfa_offset 8 + .cfi_offset %rdi,-8 pushq %rsi + .cfi_adjust_cfa_offset 8 + .cfi_offset %rsi,-16 movq $3,%rdi /* SIG_SETMASK */ leaq 72(%rdx),%rsi /* (sigset_t*)set */ movq $0,%rdx /* (sigset_t*)oset */ @@ -95,10 +109,23 @@ ENTRY(__siglongjmp) call PIC_PLT(CNAME(_sigprocmask)) addq $0x8,%rsp popq %rsi + .cfi_adjust_cfa_offset -8 + .cfi_restore %rsi popq %rdi /* jmpbuf */ + .cfi_adjust_cfa_offset -8 + .cfi_restore %rdi 2: movq %rdi,%rdx movq %rsi,%rax /* retval */ + .cfi_def_cfa %rdx,16 + .cfi_offset %rbx,8 + .cfi_offset %rbp,24 + .cfi_offset %r12,32 + .cfi_offset %r13,40 + .cfi_offset %r14,48 + .cfi_offset %r15,56 movq 0(%rdx),%rcx + .cfi_undefined %rcx + .cfi_return_column %rcx movq 8(%rdx),%rbx movq 16(%rdx),%rsp movq 24(%rdx),%rbp diff --git a/lib/libc/amd64/string/bcopy.S b/lib/libc/amd64/string/bcopy.S index cc38f47..378cb45 100644 --- a/lib/libc/amd64/string/bcopy.S +++ b/lib/libc/amd64/string/bcopy.S @@ -54,9 +54,12 @@ ENTRY(bcopy) movq %rdi,%rax /* return dst */ #else xchgq %rdi,%rsi + .cfi_register %rdi,%rsi + .cfi_register %rsi,%rdi #endif movq %rdx,%rcx movq %rdi,%r8 + .cfi_undefined %r8 subq %rsi,%r8 cmpq %rcx,%r8 /* overlapping? */ jb 1f @@ -64,6 +67,8 @@ ENTRY(bcopy) shrq $3,%rcx /* copy by words */ rep movsq + .cfi_undefined %rdi + .cfi_undefined %rsi movq %rdx,%rcx andq $7,%rcx /* any bytes left? */ rep @@ -71,7 +76,9 @@ ENTRY(bcopy) ret 1: addq %rcx,%rdi /* copy backwards. */ + .cfi_undefined %rdi addq %rcx,%rsi + .cfi_undefined %rsi std andq $7,%rcx /* any fractional bytes? */ decq %rdi diff --git a/lib/libc/amd64/string/bzero.S b/lib/libc/amd64/string/bzero.S index cf46a2a..e2acb56 100644 --- a/lib/libc/amd64/string/bzero.S +++ b/lib/libc/amd64/string/bzero.S @@ -27,6 +27,7 @@ ENTRY(bzero) negq %rcx andq $7,%rcx subq %rcx,%rsi + .cfi_undefined %rsi rep /* zero until word aligned */ stosb =20 diff --git a/lib/libc/amd64/string/memcmp.S b/lib/libc/amd64/string/memcmp.S index 66d64a0..a794238 100644 --- a/lib/libc/amd64/string/memcmp.S +++ b/lib/libc/amd64/string/memcmp.S @@ -17,6 +17,8 @@ ENTRY(memcmp) shrq $3,%rcx repe cmpsq + .cfi_undefined %rsi + .cfi_undefined %rdi jne L5 /* do we match so far? */ =20 movq %rdx,%rcx /* compare remainder by bytes */ diff --git a/lib/libc/amd64/string/memset.S b/lib/libc/amd64/string/memset.S index 84d1562..bec8654 100644 --- a/lib/libc/amd64/string/memset.S +++ b/lib/libc/amd64/string/memset.S @@ -16,6 +16,7 @@ ENTRY(memset) andq $0xff,%rax movq %rdx,%rcx movq %rdi,%r11 + .cfi_undefined %r11 =20 cld /* set fill direction forward */ =20 @@ -45,6 +46,7 @@ ENTRY(memset) movq %rdx,%rcx /* set until word aligned */ rep stosb + .cfi_undefined %rdi =20 movq %r8,%rcx shrq $3,%rcx /* set by words */ @@ -55,6 +57,7 @@ ENTRY(memset) andq $7,%rcx L1: rep stosb + .cfi_undefined %rdi movq %r11,%rax =20 ret diff --git a/lib/libc/amd64/string/stpcpy.S b/lib/libc/amd64/string/stpcpy.S index 52ac69c..95054dc 100644 --- a/lib/libc/amd64/string/stpcpy.S +++ b/lib/libc/amd64/string/stpcpy.S @@ -24,7 +24,9 @@ __FBSDID("$FreeBSD$"); ENTRY(stpcpy) __stpcpy: movabsq $0x0101010101010101,%r8 + .cfi_undefined %r8 movabsq $0x8080808080808080,%r9 + .cfi_undefined %r9 =20 /* * Align source to a word boundary. @@ -35,8 +37,10 @@ __stpcpy: je .Lword_aligned movb (%rsi),%dl incq %rsi + .cfi_undefined %rsi movb %dl,(%rdi) incq %rdi + .cfi_undefined %rdi testb %dl,%dl jne .Lalign movq %rdi,%rax @@ -51,6 +55,7 @@ __stpcpy: movq (%rsi),%rdx movq %rdx,%rcx addq $8,%rsi + .cfi_undefined %rsi subq %r8,%rcx testq %r9,%rcx je .Lloop @@ -64,6 +69,7 @@ __stpcpy: testb %dl,%dl /* 1st byte =3D=3D 0? */ je .Ldone incq %rdi + .cfi_undefined %rdi =20 shrq $8,%rdx movb %dl,(%rdi) diff --git a/lib/libc/amd64/string/strcat.S b/lib/libc/amd64/string/strcat.S index 7b5a1dd..daaaac1 100644 --- a/lib/libc/amd64/string/strcat.S +++ b/lib/libc/amd64/string/strcat.S @@ -33,6 +33,7 @@ ENTRY(strcat) .Lscan_loop: movq (%rdi),%rdx addq $8,%rdi + .cfi_undefined %rdi subq %r8,%rdx testq %r9,%rdx je .Lscan_loop @@ -91,6 +92,7 @@ ENTRY(strcat) je .Lcopy_aligned movb (%rsi),%dl incq %rsi + .cfi_undefined %rsi movb %dl,(%rdi) incq %rdi testb %dl,%dl @@ -101,10 +103,12 @@ ENTRY(strcat) .Lcopy_loop: movq %rdx,(%rdi) addq $8,%rdi + .cfi_undefined %rdi .Lcopy_aligned: movq (%rsi),%rdx movq %rdx,%rcx addq $8,%rsi + .cfi_undefined %rsi subq %r8,%rcx testq %r9,%rcx je .Lcopy_loop diff --git a/lib/libc/amd64/string/strcmp.S b/lib/libc/amd64/string/strcmp.S index 07009c1..2132187 100644 --- a/lib/libc/amd64/string/strcmp.S +++ b/lib/libc/amd64/string/strcmp.S @@ -20,8 +20,10 @@ ENTRY(strcmp) je .Ls1aligned movb (%rdi),%al incq %rdi + .cfi_undefined %rdi movb (%rsi),%dl incq %rsi + .cfi_undefined %rsi testb %al,%al je .Ldone cmpb %al,%dl diff --git a/lib/libc/amd64/sys/brk.S b/lib/libc/amd64/sys/brk.S index 4048ae6..76e6280 100644 --- a/lib/libc/amd64/sys/brk.S +++ b/lib/libc/amd64/sys/brk.S @@ -42,14 +42,18 @@ __FBSDID("$FreeBSD$"); .globl HIDENAME(minbrk) ENTRY(_brk) pushq %rdi + .cfi_adjust_cfa_offset 8 jmp ok END(_brk) =20 ENTRY(brk) pushq %rdi + .cfi_adjust_cfa_offset 8 movq %rdi,%rax + .cfi_undefined %rax #ifdef PIC movq PIC_GOT(HIDENAME(minbrk)),%rdx + .cfi_undefined %rdx cmpq %rax,(%rdx) #else cmpq %rax,HIDENAME(minbrk)(%rip) @@ -60,8 +64,10 @@ ENTRY(brk) #else movq HIDENAME(minbrk)(%rip),%rdi #endif + .cfi_undefined %rdi ok: movq $SYS_break,%rax + .cfi_undefined %rax KERNCALL jb err movq 0(%rsp),%rax @@ -73,9 +79,11 @@ ok: #endif movq $0,%rax popq %rdi + .cfi_adjust_cfa_offset -8 ret err: addq $8, %rsp + .cfi_adjust_cfa_offset -8 jmp HIDENAME(cerror) END(brk) =20 diff --git a/lib/libc/amd64/sys/cerror.S b/lib/libc/amd64/sys/cerror.S index d01cf4a..43032e4 100644 --- a/lib/libc/amd64/sys/cerror.S +++ b/lib/libc/amd64/sys/cerror.S @@ -48,12 +48,21 @@ __FBSDID("$FreeBSD$"); .globl CNAME(__error) .type CNAME(__error),@function HIDENAME(cerror): + .cfi_startproc pushq %rax + .cfi_adjust_cfa_offset 8 + .cfi_offset %rax,0 call PIC_PLT(CNAME(__error)) popq %rcx + .cfi_adjust_cfa_offset -8 + .cfi_undefined %rcx + .cfi_register %rax,%rcx movl %ecx,(%rax) movq $-1,%rax + .cfi_undefined %rax movq $-1,%rdx + .cfi_undefined %rdx ret + .cfi_endproc =20 .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/amd64/sys/exect.S b/lib/libc/amd64/sys/exect.S index 04a97ed..ce5e717 100644 --- a/lib/libc/amd64/sys/exect.S +++ b/lib/libc/amd64/sys/exect.S @@ -41,11 +41,17 @@ __FBSDID("$FreeBSD$"); =20 ENTRY(exect) movq $SYS_execve,%rax + .cfi_undefined %rax pushfq + .cfi_adjust_cfa_offset 8 popq %r8 + .cfi_adjust_cfa_offset -8 + .cfi_undefined %r8 orq $PSL_T,%r8 pushq %r8 + .cfi_adjust_cfa_offset 8 popfq + .cfi_adjust_cfa_offset -8 KERNCALL jmp HIDENAME(cerror) END(exect) diff --git a/lib/libc/amd64/sys/getcontext.S b/lib/libc/amd64/sys/getcontex= t.S index 1128796..94c894c 100644 --- a/lib/libc/amd64/sys/getcontext.S +++ b/lib/libc/amd64/sys/getcontext.S @@ -40,10 +40,22 @@ __FBSDID("$FreeBSD$"); .set getcontext,__sys_getcontext ENTRY(__sys_getcontext) movq (%rsp),%rsi /* save getcontext return address */ + .cfi_undefined %rsi mov $SYS_getcontext,%rax + .cfi_undefined %rax KERNCALL jb HIDENAME(cerror) addq $8,%rsp /* remove stale (setcontext) return address */ + /* + * The instruction above adjusted top of the stack so that the stack + * does not contain a return address anymore. But, due to the red + * zone existence, return address value right below the top of stack + * is non-volatile. Try to describe the trick to unwinder by claiming + * that the standard call frame is one long word below top of the + * stack. + */ + .cfi_adjust_cfa_offset 8 + .cfi_return_column %rsi jmp *%rsi /* restore return address */ END(__sys_getcontext) =20 diff --git a/lib/libc/amd64/sys/pipe.S b/lib/libc/amd64/sys/pipe.S index 8d089db..6eee962 100644 --- a/lib/libc/amd64/sys/pipe.S +++ b/lib/libc/amd64/sys/pipe.S @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); .set pipe,__sys_pipe ENTRY(__sys_pipe) mov $SYS_pipe,%rax + .cfi_undefined %rax KERNCALL jb HIDENAME(cerror) movl %eax,(%rdi) /* %rdi is preserved by syscall */ diff --git a/lib/libc/amd64/sys/ptrace.S b/lib/libc/amd64/sys/ptrace.S index 9c4628d..5dbde65 100644 --- a/lib/libc/amd64/sys/ptrace.S +++ b/lib/libc/amd64/sys/ptrace.S @@ -40,8 +40,10 @@ __FBSDID("$FreeBSD$"); =20 ENTRY(ptrace) xorl %eax,%eax + .cfi_undefined %rax #ifdef PIC movq PIC_GOT(CNAME(errno)),%r8 + .cfi_undefined %r8 movl %eax,(%r8) #else movl %eax,CNAME(errno)(%rip) diff --git a/lib/libc/amd64/sys/reboot.S b/lib/libc/amd64/sys/reboot.S index fd04ef4..57fa2df 100644 --- a/lib/libc/amd64/sys/reboot.S +++ b/lib/libc/amd64/sys/reboot.S @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); .set reboot,__sys_reboot ENTRY(__sys_reboot) mov $SYS_reboot,%rax + .cfi_undefined %rax KERNCALL jb HIDENAME(cerror) iretq diff --git a/lib/libc/amd64/sys/sbrk.S b/lib/libc/amd64/sys/sbrk.S index 0332aae..f0e3c6b 100644 --- a/lib/libc/amd64/sys/sbrk.S +++ b/lib/libc/amd64/sys/sbrk.S @@ -49,16 +49,22 @@ HIDENAME(curbrk): .quad CNAME(_end) =20 ENTRY(sbrk) pushq %rdi + .cfi_adjust_cfa_offset 8 movq %rdi,%rcx + .cfi_register %rdi,%rcx #ifdef PIC movq PIC_GOT(HIDENAME(curbrk)),%rdx + .cfi_undefined %rdx movq (%rdx),%rax + .cfi_undefined %rax #else movq HIDENAME(curbrk)(%rip),%rax + .cfi_undefined %rax #endif testq %rcx,%rcx jz back addq %rax,%rdi + .cfi_undefined %rdi mov $SYS_break,%eax KERNCALL jb err @@ -69,6 +75,7 @@ ENTRY(sbrk) movq HIDENAME(curbrk)(%rip),%rax #endif movq 0(%rsp), %rcx + .cfi_undefined %rcx #ifdef PIC addq %rcx,(%rdx) #else @@ -76,9 +83,11 @@ ENTRY(sbrk) #endif back: addq $8, %rsp + .cfi_adjust_cfa_offset -8 ret err: addq $8, %rsp + .cfi_adjust_cfa_offset -8 jmp HIDENAME(cerror) END(sbrk) =20 diff --git a/lib/libc/amd64/sys/setlogin.S b/lib/libc/amd64/sys/setlogin.S index a451491..86b220c 100644 --- a/lib/libc/amd64/sys/setlogin.S +++ b/lib/libc/amd64/sys/setlogin.S @@ -46,10 +46,12 @@ __FBSDID("$FreeBSD$"); .set setlogin,__sys_setlogin ENTRY(__sys_setlogin) mov $SYS_setlogin,%rax + .cfi_undefined %rax KERNCALL jb HIDENAME(cerror) #ifdef PIC movq PIC_GOT(CNAME(_logname_valid)),%rdx + .cfi_undefined %rdx movl $0,(%rdx) #else movl $0,CNAME(_logname_valid)(%rip) diff --git a/lib/libc/amd64/sys/vfork.S b/lib/libc/amd64/sys/vfork.S index 2afba58..c2673da 100644 --- a/lib/libc/amd64/sys/vfork.S +++ b/lib/libc/amd64/sys/vfork.S @@ -44,12 +44,18 @@ __FBSDID("$FreeBSD$"); .set vfork,__sys_vfork ENTRY(__sys_vfork) popq %rsi /* fetch return address (%rsi preserved) */ + /* See a comment in getcontext.S */ + .cfi_adjust_cfa_offset -8 + .cfi_undefined %rsi + .cfi_return_column %rsi mov $SYS_vfork,%rax + .cfi_undefined %rax KERNCALL jb 1f jmp *%rsi 1: pushq %rsi + .cfi_adjust_cfa_offset 8 jmp HIDENAME(cerror) END(__sys_vfork) =20 diff --git a/lib/libthr/arch/amd64/amd64/_umtx_op_err.S b/lib/libthr/arch/a= md64/amd64/_umtx_op_err.S index b54fe64..36d6cf4 100644 --- a/lib/libthr/arch/amd64/amd64/_umtx_op_err.S +++ b/lib/libthr/arch/amd64/amd64/_umtx_op_err.S @@ -29,10 +29,20 @@ #include #include =20 -#define RSYSCALL_ERR(x) ENTRY(__CONCAT(x, _err)); \ - mov __CONCAT($SYS_,x),%rax; KERNCALL; ret;=20 +#define RSYSCALL_ERR(x) \ + ENTRY(__CONCAT(x, _err)); \ + mov __CONCAT($SYS_,x),%rax; \ + .cfi_undefined %rax; \ + KERNCALL; \ + ret; \ + END(__CONCAT(x, _err)) =20 -#define KERNCALL movq %rcx, %r10; syscall +#define KERNCALL \ + movq %rcx,%r10; \ + .cfi_undefined %r10; \ + .cfi_register %rcx,%r10; \ + syscall; \ + .cfi_undefined %rax,%rdx =20 RSYSCALL_ERR(_umtx_op) =20 diff --git a/sys/amd64/include/asm.h b/sys/amd64/include/asm.h index 7efd642..75603ec 100644 --- a/sys/amd64/include/asm.h +++ b/sys/amd64/include/asm.h @@ -59,25 +59,37 @@ #define _START_ENTRY .text; .p2align 4,0x90 =20 #define _ENTRY(x) _START_ENTRY; \ - .globl CNAME(x); .type CNAME(x),@function; CNAME(x): + .globl CNAME(x); .type CNAME(x),@function; \ + CNAME(x): .cfi_startproc =20 #ifdef PROF -#define ALTENTRY(x) _ENTRY(x); \ - pushq %rbp; movq %rsp,%rbp; \ +#define ALTENTRY(x) _ENTRY(x); \ + pushq %rbp; \ + .cfi_adjust_cfa_offset 8; \ + .cfi_offset %rbp,0 \ + movq %rsp,%rbp; \ call PIC_PLT(HIDENAME(mcount)); \ - popq %rbp; \ + popq %rbp; \ + .cfi_adjust_cfa_offset -8; \ + .cfi_restore %rbp; \ jmp 9f -#define ENTRY(x) _ENTRY(x); \ - pushq %rbp; movq %rsp,%rbp; \ +#define ENTRY(x) _ENTRY(x); \ + pushq %rbp; \ + .cfi_adjust_cfa_offset 8; \ + .cfi_offset %rbp,0 \ + movq %rsp,%rbp; \ call PIC_PLT(HIDENAME(mcount)); \ - popq %rbp; \ + popq %rbp; \ + .cfi_adjust_cfa_offset -8; \ + .cfi_restore %rbp; \ 9: #else #define ALTENTRY(x) _ENTRY(x) #define ENTRY(x) _ENTRY(x) #endif =20 -#define END(x) .size x, . - x +#define END(x) .cfi_endproc; \ + .size x, . - x =20 #define RCSID(x) .text; .asciz x =20 --+y7rRxfO4bOZsSs1 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlBxnaUACgkQC3+MBN1Mb4jQygCg87K1V2LfE7UKv5xm+Pn8qx1G iNAAoJZj+vftlW4y42HycBsJn5yQ2Hy7 =Wbsk -----END PGP SIGNATURE----- --+y7rRxfO4bOZsSs1--