Patchwork Enable unwind info in libc-start.c and backtrace.c

login
register
mail settings
Submitter Wilco Dijkstra
Date Aug. 9, 2017, 11:46 a.m.
Message ID <DB6PR0801MB2053DFC14FB872257FCA400F838B0@DB6PR0801MB2053.eurprd08.prod.outlook.com>
Download mbox | patch
Permalink /patch/22006/
State New
Headers show

Comments

Wilco Dijkstra - Aug. 9, 2017, 11:46 a.m.
After feedback on https://sourceware.org/ml/libc-alpha/2017-07/msg01010.html
here is the updated patch:

Add unwind info to __libc_start_main so that unwinding continues one
extra level to _start.  Similarly add unwind info to backtrace.
Given many targets require this, do this in a general way and remove
-funwind-tables (or -fexceptions - which is identical in C) from several
target makefiles.

ChangeLog:
2017-08-09  Wilco Dijkstra  <wdijkstr@arm.com>

        * sysdeps/aarch64/Makefile: Build libc-start.c with -fexceptions.
        * csu/Makefile: Add -funwind-tables to libc-start.c.
        * debug/Makefile: Add -funwind-tables to backtrace.c.
        * sysdeps/aarch64/Makefile: Remove CFLAGS-backtrace.c.
        * sysdeps/arm/Makefile: Likewise.
        * sysdeps/i386/Makefile: Likewise.
        * sysdeps/m68k/Makefile: Likewise.
        * sysdeps/mips/Makefile: Likewise.
        * sysdeps/nios2/Makefile: Likewise.
        * sysdeps/sh/Makefile: Likewise.
        * sysdeps/sparc/Makefile: Likewise.
--
Carlos O'Donell - Aug. 9, 2017, 12:45 p.m.
On 08/09/2017 07:46 AM, Wilco Dijkstra wrote:
> After feedback on https://sourceware.org/ml/libc-alpha/2017-07/msg01010.html
> here is the updated patch:
> 
> Add unwind info to __libc_start_main so that unwinding continues one
> extra level to _start.  Similarly add unwind info to backtrace.
> Given many targets require this, do this in a general way and remove
> -funwind-tables (or -fexceptions - which is identical in C) from several
> target makefiles.
> 
> ChangeLog:
> 2017-08-09  Wilco Dijkstra  <wdijkstr@arm.com>
> 
>         * sysdeps/aarch64/Makefile: Build libc-start.c with -fexceptions.
>         * csu/Makefile: Add -funwind-tables to libc-start.c.
>         * debug/Makefile: Add -funwind-tables to backtrace.c.
>         * sysdeps/aarch64/Makefile: Remove CFLAGS-backtrace.c.
>         * sysdeps/arm/Makefile: Likewise.
>         * sysdeps/i386/Makefile: Likewise.
>         * sysdeps/m68k/Makefile: Likewise.
>         * sysdeps/mips/Makefile: Likewise.
>         * sysdeps/nios2/Makefile: Likewise.
>         * sysdeps/sh/Makefile: Likewise.
>         * sysdeps/sparc/Makefile: Likewise.

This looks god to me, but I'd like to know what machines you've tested on?

If you tested on aarch64, i386, and arm (v7), then I'd say you've done enough
to show it work on 64-bit and 32-bit for relevant machines.
Andreas Schwab - Aug. 9, 2017, 1 p.m.
On Aug 09 2017, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:

>         * sysdeps/aarch64/Makefile: Build libc-start.c with -fexceptions.

This is no longer part of the patch.

Andreas.

Patch

diff --git a/csu/Makefile b/csu/Makefile
index 88646b6e8f068c09c5743fd908b08d15064294ee..490d0b0f3b63318381e59fc35038801f682d20a2 100644
--- a/csu/Makefile
+++ b/csu/Makefile
@@ -82,6 +82,9 @@  extra-objs += $(crtstuff:=.o)
 extra-objs += abi-note.o init.o
 asm-CPPFLAGS += -I$(objpfx).
 
+# Enable unwinding so backtrace unwinds to __libc_start_main
+CFLAGS-libc-start.c += -funwind-tables
+
 include ../Rules
 
 # Make these in the lib pass so they're available in time to link things with.
diff --git a/debug/Makefile b/debug/Makefile
index cd4975c35b70fe4c52fc6bbedb0f88179463af9c..620a0b71f5919d41cc5cb41d0943193d8e7b6ac5 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -59,7 +59,7 @@  static-only-routines := warning-nop stack_chk_fail_local
 CFLAGS-stack_chk_fail.c = $(no-stack-protector)
 CFLAGS-stack_chk_fail_local.c = $(no-stack-protector)
 
-CFLAGS-backtrace.c = -fno-omit-frame-pointer
+CFLAGS-backtrace.c = -fno-omit-frame-pointer -funwind-tables
 CFLAGS-sprintf_chk.c = $(libio-mtsafe)
 CFLAGS-snprintf_chk.c = $(libio-mtsafe)
 CFLAGS-vsprintf_chk.c = $(libio-mtsafe)
diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile
index 562c1373aebee6ffb4ff5c2071a23d007a8e07ba..5f3e20371accfb001de6dff342bb323b424324ca 100644
--- a/sysdeps/aarch64/Makefile
+++ b/sysdeps/aarch64/Makefile
@@ -1,9 +1,5 @@ 
 long-double-fcts = yes
 
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
-
 ifeq ($(subdir),elf)
 sysdep-dl-routines += tlsdesc dl-tlsdesc
 gen-as-const-headers += dl-link.sym
diff --git a/sysdeps/arm/Makefile b/sysdeps/arm/Makefile
index 2849aeda4238997975c5a8096da474e54da26932..ad2042b93a156867f586bedaaba4b120a93f676c 100644
--- a/sysdeps/arm/Makefile
+++ b/sysdeps/arm/Makefile
@@ -51,11 +51,6 @@  sysdep_routines += $(aeabi_constants) $(aeabi_routines)
 static-only-routines += $(aeabi_constants) aeabi_read_tp
 shared-only-routines += libc-aeabi_read_tp
 
-# In order for unwinding to fail when it falls out of main, we need a
-# cantunwind marker.  There's one in start.S.  To make sure we reach it, add
-# unwind tables for __libc_start_main.
-CFLAGS-libc-start.c += -fexceptions
-
 sysdep_routines += arm-unwind-resume
 shared-only-routines += arm-unwind-resume
 endif
@@ -64,10 +59,6 @@  ifeq ($(subdir),gmon)
 sysdep_routines += arm-mcount
 endif
 
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
-
 ifeq ($(subdir),rt)
 librt-sysdep_routines += rt-aeabi_unwind_cpp_pr1 rt-arm-unwind-resume
 librt-shared-only-routines += rt-aeabi_unwind_cpp_pr1 rt-arm-unwind-resume
diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile
index e30e1339f0554dd53be1ab881cb4df04de820792..a1500454e5a977415b8bd120326f3db104d18df2 100644
--- a/sysdeps/i386/Makefile
+++ b/sysdeps/i386/Makefile
@@ -19,10 +19,6 @@  CFLAGS-dl-load.c += -Wno-unused
 CFLAGS-dl-reloc.c += -Wno-unused
 endif
 
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -fexceptions
-endif
-
 # Most of the glibc routines don't ever call user defined callbacks
 # nor use any FPU or SSE* and as such don't need bigger %esp alignment
 # than 4 bytes.
diff --git a/sysdeps/m68k/Makefile b/sysdeps/m68k/Makefile
index 26539fa01d38a5ba1260cb1fda153470513d2e29..b6910014f8fe75591026381d4b6a9e02301740d7 100644
--- a/sysdeps/m68k/Makefile
+++ b/sysdeps/m68k/Makefile
@@ -40,10 +40,6 @@  ifeq ($(subdir),setjmp)
 CFLAGS-setjmp.c := -fno-omit-frame-pointer
 endif
 
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
-
 ifeq ($(subdir),elf)
 CFLAGS-rtld.c += -Wno-uninitialized -Wno-unused
 endif
diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
index 7c1d77941ec154b460af9b2581cec7e82141acdf..fd891ddf09855adaac3d50f57ca9bd245fbc16e2 100644
--- a/sysdeps/mips/Makefile
+++ b/sysdeps/mips/Makefile
@@ -12,10 +12,6 @@  librt-sysdep_routines += rt-sysdep
 librt-shared-only-routines += rt-sysdep
 endif
 
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
-
 ifeq ($(subdir),csu)
 CPPFLAGS-crti.S += $(pic-ccflag)
 CPPFLAGS-crtn.S += $(pic-ccflag)
diff --git a/sysdeps/nios2/Makefile b/sysdeps/nios2/Makefile
index 75cab5e5b8fc04e916ced8e1b9c3a8ecc657b85d..9ceab11297a7d215e3a30d3ecf2210029a89a51b 100644
--- a/sysdeps/nios2/Makefile
+++ b/sysdeps/nios2/Makefile
@@ -29,7 +29,3 @@  endif
 ifeq ($(subdir),csu)
 gen-as-const-headers += tcb-offsets.sym
 endif
-
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
diff --git a/sysdeps/sh/Makefile b/sysdeps/sh/Makefile
index 0c6db9a9d41d56defb946fcc31e0767c7a853611..de8fa0bc0e81e8b7e1ef946b7106408cf4ac7cd1 100644
--- a/sysdeps/sh/Makefile
+++ b/sysdeps/sh/Makefile
@@ -5,7 +5,3 @@  endif
 ifeq ($(subdir),gmon)
 sysdep_routines += _mcount
 endif
-
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
index 31aaeaed8f8e601b578908e13a6f99352346f753..3f0c0964002560f03817905f390821aef176d52c 100644
--- a/sysdeps/sparc/Makefile
+++ b/sysdeps/sparc/Makefile
@@ -3,10 +3,6 @@  long-double-fcts = yes
 
 pie-ccflag = -fPIE
 
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
-
 ifeq ($(subdir),gmon)
 sysdep_routines += sparc-mcount
 endif