Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Mon, 27 Apr 2015 13:32:35 +0200
From: Alex Dowad <alexinbeijing@...il.com>
To: musl@...ts.openwall.com
Subject: [PATCH] generate debug_frame info for __syscall_cp_asm (i386) so gdb can get backtrace

__syscall_cp_asm needs to use EBP to pass the 6th argument to syscalls with
6 arguments, so it can't use it for a frame pointer. Without frame pointers,
GDB can only show backtraces if it gets CFI information from a .debug_frame
or .eh_frame section.

GCC automatically generates .debug_frame info for all the functions implemented
in C, so GDB can get backtraces for them. But the assembler can't generate
.debug_frame info for functions implemented in asm, unless you tell it how to
find the call frame.

With no backtraces, GDB's "catch syscall" is almost useless for syscalls which
are implemented using syscall_cp, like close and writev. Adding the CFI info makes
it possible to catch these syscalls and find out exactly where a program is using
them from.
---
 src/thread/i386/syscall_cp.s | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Dear musl devs,

Please have a look at this patch, and CC me on any discussion. (I've never worked on
musl before and haven't joined the mailing list.) Your feedback will be appreciated.
(Just to let you know, I have build-tested this code and tried it in gdb.)

If you would like to add similar stack frame debug information to other asm functions,
I would be happy to send more patches. The CFI directives can be made more concise
using asm macros if desired.

By the way, I absolutely and utterly LOVE your Makefile and configure scripts. They're
so... so SANE. I never thought a configure script could make me this happy! Thank you!

Regards,
Alex Dowad <alexinbeijing@...il.com>

diff --git a/src/thread/i386/syscall_cp.s b/src/thread/i386/syscall_cp.s
index 7dce1eb..baba145 100644
--- a/src/thread/i386/syscall_cp.s
+++ b/src/thread/i386/syscall_cp.s
@@ -9,12 +9,23 @@
 .global __syscall_cp_asm
 .hidden __syscall_cp_asm
 .type   __syscall_cp_asm,@function
+.cfi_sections .debug_frame
+.cfi_startproc
 __syscall_cp_asm:
 	mov 4(%esp),%ecx
 	pushl %ebx
+.cfi_adjust_cfa_offset 4
+.cfi_offset ebx,-8
 	pushl %esi
+.cfi_adjust_cfa_offset 4
+.cfi_offset esi,-12
 	pushl %edi
+.cfi_adjust_cfa_offset 4
+.cfi_offset edi,-16
 	pushl %ebp
+.cfi_adjust_cfa_offset 4
+.cfi_offset ebp,-20
 __cp_begin:
 	movl (%ecx),%eax
 	testl %eax,%eax
@@ -29,10 +40,19 @@ __cp_begin:
 	int $128
 __cp_end:
 	popl %ebp
+.cfi_adjust_cfa_offset -4
+.cfi_restore ebp
 	popl %edi
+.cfi_adjust_cfa_offset -4
+.cfi_restore edi
 	popl %esi
+.cfi_adjust_cfa_offset -4
+.cfi_restore esi
 	popl %ebx
+.cfi_adjust_cfa_offset -4
+.cfi_restore ebx
 	ret
+.cfi_endproc
 __cp_cancel:
 	popl %ebp
 	popl %edi
-- 
2.0.0.GIT

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.