diff mbox series

musl: add debug information for mipsel syscalls

Message ID 20200624231423.3717-1-daniel.santos@pobox.com
State Changes Requested
Headers show
Series musl: add debug information for mipsel syscalls | expand

Commit Message

Daniel Santos June 24, 2020, 11:14 p.m. UTC
This is split into two patches to ease reviewing, as it must be renamed
to *.S in order to be preprocessed.

Co-Authored-By: Daniele Tamino <dtamino@irobot.com>
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
 ...ebug-information-to-__syscall_cp_asm.patch | 100 ++++++++++++++++++
 .../221-mipsel-preprocess-syscall_cp.s.patch  |  18 ++++
 2 files changed, 118 insertions(+)
 create mode 100644 toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch
 create mode 100644 toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch

Comments

Hauke Mehrtens July 4, 2020, 3:22 p.m. UTC | #1
On 6/25/20 1:14 AM, Daniel Santos wrote:
> This is split into two patches to ease reviewing, as it must be renamed
> to *.S in order to be preprocessed.
> 
> Co-Authored-By: Daniele Tamino <dtamino@irobot.com>
> Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
> ---
>  ...ebug-information-to-__syscall_cp_asm.patch | 100 ++++++++++++++++++
>  .../221-mipsel-preprocess-syscall_cp.s.patch  |  18 ++++
>  2 files changed, 118 insertions(+)
>  create mode 100644 toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch
>  create mode 100644 toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch
> 
> diff --git a/toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch b/toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch
> new file mode 100644
> index 0000000000..0aa9330bd4
> --- /dev/null
> +++ b/toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch
> @@ -0,0 +1,100 @@
> +From 6ce77039943af4ca51ebf1385fd6ed01ecce8159 Mon Sep 17 00:00:00 2001
> +From: Daniel Santos <daniel.santos@pobox.com>
> +Date: Wed, 24 Jun 2020 14:45:08 -0500
> +Subject: mipsel: Add debug information to __syscall_cp_asm
> +
> +This is the function called for interruptable / repeatable syscalls like
> +nanosleep.  Without this patch, attaching a debugger to a program making
> +such a syscall results in the debugger being completely unable to
> +perform a backtrace.
> +
> +Co-Authored-By: Daniele Tamino <dtamino@irobot.com>
> +Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
> +---
> + src/thread/mips/syscall_cp.s | 41 +++++++++++++++++++++++++++++++++++-
> + 1 file changed, 40 insertions(+), 1 deletion(-)
> +
> +diff --git a/src/thread/mips/syscall_cp.s b/src/thread/mips/syscall_cp.s
> +index d2846264..d39bff59 100644
> +--- a/src/thread/mips/syscall_cp.s
> ++++ b/src/thread/mips/syscall_cp.s
> +@@ -1,4 +1,14 @@
> ++.section	.mdebug.abi32
> ++.previous
> + .set    noreorder
> ++.cfi_sections	.debug_frame
> ++.abicalls
> ++#ifdef __PIC__
> ++	.option	pic2
> ++#else
> ++	.option	pic0
> ++#endif
> ++.text
> + 
> + .global __cp_begin
> + .hidden __cp_begin
> +@@ -9,12 +19,32 @@
> + .global __cp_cancel
> + .hidden __cp_cancel
> + .type   __cp_cancel,@function
> +-.hidden __cancel
> ++.hidden __cancel	/* long __cancel() in src/thread/pthread_cancel.c */
> + .global __syscall_cp_asm
> + .hidden __syscall_cp_asm
> + .type   __syscall_cp_asm,@function
> ++
> ++/*
> ++long __syscall_cp_asm(
> ++	volatile int *cancel,
> ++	syscall_arg_t nr,
> ++	syscall_arg_t u,
> ++	syscall_arg_t v,
> ++	syscall_arg_t w,
> ++	syscall_arg_t x,
> ++	syscall_arg_t y,
> ++	syscall_arg_t z)
> ++*/
> ++
> ++	.ent	__syscall_cp_asm
> ++	.frame	$sp, 32, $ra
> ++	.mask	0x00000000, 0
> ++	.fmask	0x00000000, 0
> ++	.cfi_startproc
> ++	.cfi_return_column $ra
> + __syscall_cp_asm:
> + 	subu    $sp, $sp, 32
> ++	.cfi_adjust_cfa_offset 32
> + __cp_begin:
> + 	lw      $4, 0($4)
> + 	bne     $4, $0, __cp_cancel
> +@@ -35,14 +65,17 @@ __cp_begin:
> + __cp_end:
> + 	beq     $7, $0, 1f
> + 	addu    $sp, $sp, 32
> ++	.cfi_adjust_cfa_offset -32
> + 	subu    $2, $0, $2
> + 1:	jr      $ra
> + 	nop
> + 
> + __cp_cancel:
> + 	move    $2, $ra
> ++	.cfi_register $ra, $2
> + 	bal     1f
> + 	addu    $sp, $sp, 32
> ++	.cfi_adjust_cfa_offset -32
> + 	.gpword .
> + 	.gpword __cancel
> + 1:	lw      $3, ($ra)
> +@@ -51,3 +84,9 @@ __cp_cancel:
> + 	addu    $25, $25, $3
> + 	jr      $25
> + 	move    $ra, $2
> ++	.cfi_restore $ra
> ++#ifdef __ELF__
> ++	.size __syscall_cp_asm,.-__syscall_cp_asm
> ++#endif
> ++	.end	__syscall_cp_asm
> ++	.cfi_endproc
> +-- 
> +2.24.1
> +
> diff --git a/toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch b/toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch
> new file mode 100644
> index 0000000000..a4eb8fed51
> --- /dev/null
> +++ b/toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch
> @@ -0,0 +1,18 @@
> +From 76cfae6e5a22bbbbdca17ff2ffa196b3ad2a3537 Mon Sep 17 00:00:00 2001
> +From: Daniel Santos <daniel.santos@pobox.com>
> +Date: Wed, 24 Jun 2020 14:46:15 -0500
> +Subject: mipsel: preprocess syscall_cp.s
> +
> +Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
> +---
> + src/thread/mips/{syscall_cp.s => syscall_cp.S} | 0
> + 1 file changed, 0 insertions(+), 0 deletions(-)
> + rename src/thread/mips/{syscall_cp.s => syscall_cp.S} (100%)
> +
> +diff --git a/src/thread/mips/syscall_cp.s b/src/thread/mips/syscall_cp.S
> +similarity index 100%
> +rename from src/thread/mips/syscall_cp.s
> +rename to src/thread/mips/syscall_cp.S
> +-- 
> +2.24.1
> +

Hi,

Thank you for also sending this upstream. I will wait for a new version
which addresses the comments from Rich:
https://www.openwall.com/lists/musl/2020/06/25/1

Hauke
diff mbox series

Patch

diff --git a/toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch b/toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch
new file mode 100644
index 0000000000..0aa9330bd4
--- /dev/null
+++ b/toolchain/musl/patches/220-mipsel-Add-debug-information-to-__syscall_cp_asm.patch
@@ -0,0 +1,100 @@ 
+From 6ce77039943af4ca51ebf1385fd6ed01ecce8159 Mon Sep 17 00:00:00 2001
+From: Daniel Santos <daniel.santos@pobox.com>
+Date: Wed, 24 Jun 2020 14:45:08 -0500
+Subject: mipsel: Add debug information to __syscall_cp_asm
+
+This is the function called for interruptable / repeatable syscalls like
+nanosleep.  Without this patch, attaching a debugger to a program making
+such a syscall results in the debugger being completely unable to
+perform a backtrace.
+
+Co-Authored-By: Daniele Tamino <dtamino@irobot.com>
+Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
+---
+ src/thread/mips/syscall_cp.s | 41 +++++++++++++++++++++++++++++++++++-
+ 1 file changed, 40 insertions(+), 1 deletion(-)
+
+diff --git a/src/thread/mips/syscall_cp.s b/src/thread/mips/syscall_cp.s
+index d2846264..d39bff59 100644
+--- a/src/thread/mips/syscall_cp.s
++++ b/src/thread/mips/syscall_cp.s
+@@ -1,4 +1,14 @@
++.section	.mdebug.abi32
++.previous
+ .set    noreorder
++.cfi_sections	.debug_frame
++.abicalls
++#ifdef __PIC__
++	.option	pic2
++#else
++	.option	pic0
++#endif
++.text
+ 
+ .global __cp_begin
+ .hidden __cp_begin
+@@ -9,12 +19,32 @@
+ .global __cp_cancel
+ .hidden __cp_cancel
+ .type   __cp_cancel,@function
+-.hidden __cancel
++.hidden __cancel	/* long __cancel() in src/thread/pthread_cancel.c */
+ .global __syscall_cp_asm
+ .hidden __syscall_cp_asm
+ .type   __syscall_cp_asm,@function
++
++/*
++long __syscall_cp_asm(
++	volatile int *cancel,
++	syscall_arg_t nr,
++	syscall_arg_t u,
++	syscall_arg_t v,
++	syscall_arg_t w,
++	syscall_arg_t x,
++	syscall_arg_t y,
++	syscall_arg_t z)
++*/
++
++	.ent	__syscall_cp_asm
++	.frame	$sp, 32, $ra
++	.mask	0x00000000, 0
++	.fmask	0x00000000, 0
++	.cfi_startproc
++	.cfi_return_column $ra
+ __syscall_cp_asm:
+ 	subu    $sp, $sp, 32
++	.cfi_adjust_cfa_offset 32
+ __cp_begin:
+ 	lw      $4, 0($4)
+ 	bne     $4, $0, __cp_cancel
+@@ -35,14 +65,17 @@ __cp_begin:
+ __cp_end:
+ 	beq     $7, $0, 1f
+ 	addu    $sp, $sp, 32
++	.cfi_adjust_cfa_offset -32
+ 	subu    $2, $0, $2
+ 1:	jr      $ra
+ 	nop
+ 
+ __cp_cancel:
+ 	move    $2, $ra
++	.cfi_register $ra, $2
+ 	bal     1f
+ 	addu    $sp, $sp, 32
++	.cfi_adjust_cfa_offset -32
+ 	.gpword .
+ 	.gpword __cancel
+ 1:	lw      $3, ($ra)
+@@ -51,3 +84,9 @@ __cp_cancel:
+ 	addu    $25, $25, $3
+ 	jr      $25
+ 	move    $ra, $2
++	.cfi_restore $ra
++#ifdef __ELF__
++	.size __syscall_cp_asm,.-__syscall_cp_asm
++#endif
++	.end	__syscall_cp_asm
++	.cfi_endproc
+-- 
+2.24.1
+
diff --git a/toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch b/toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch
new file mode 100644
index 0000000000..a4eb8fed51
--- /dev/null
+++ b/toolchain/musl/patches/221-mipsel-preprocess-syscall_cp.s.patch
@@ -0,0 +1,18 @@ 
+From 76cfae6e5a22bbbbdca17ff2ffa196b3ad2a3537 Mon Sep 17 00:00:00 2001
+From: Daniel Santos <daniel.santos@pobox.com>
+Date: Wed, 24 Jun 2020 14:46:15 -0500
+Subject: mipsel: preprocess syscall_cp.s
+
+Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
+---
+ src/thread/mips/{syscall_cp.s => syscall_cp.S} | 0
+ 1 file changed, 0 insertions(+), 0 deletions(-)
+ rename src/thread/mips/{syscall_cp.s => syscall_cp.S} (100%)
+
+diff --git a/src/thread/mips/syscall_cp.s b/src/thread/mips/syscall_cp.S
+similarity index 100%
+rename from src/thread/mips/syscall_cp.s
+rename to src/thread/mips/syscall_cp.S
+-- 
+2.24.1
+