Enable unwind info in libc-start.c and backtrace.c
Commit Message
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.
--
Comments
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.
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.
Carlos O'Donell wrote:
> 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.
I tried it on Arm, AArch64 and x64. I can't get GLIBC to build for i386 or i686 as
whatever magic config I try for 32-bit x86 fails during build (it gets past the config
with a newly built 64-bit GCC and binutils but then gets confused despite -m32 flags).
Wilco
On Thu, Sep 14, 2017 at 6:46 AM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> Carlos O'Donell wrote:
>
>> 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.
>
> I tried it on Arm, AArch64 and x64. I can't get GLIBC to build for i386 or i686 as
> whatever magic config I try for 32-bit x86 fails during build (it gets past the config
> with a newly built 64-bit GCC and binutils but then gets confused despite -m32 flags).
>
I use
# CC="gcc -m32 -march=i686" CXX="g++ -m32 -march=i686"
/export/gnu/import/git/sources/glibc/configure --prefix=/usr
--target=i686-linux --build=i686-linux --host=i686-linux
--enable-hardcoded-path-in-tests
to configure glibc for i686 on Linux/x86-64. It works fine.
H.J. Lu wrote:
> # CC="gcc -m32 -march=i686" CXX="g++ -m32 -march=i686"
> /export/gnu/import/git/sources/glibc/configure --prefix=/usr
> --target=i686-linux --build=i686-linux --host=i686-linux
> --enable-hardcoded-path-in-tests
>
> to configure glibc for i686 on Linux/x86-64. It works fine.
Doing it exactly like that I get:
/work/install/binutils_x64/x86_64-linux-gnu/bin/ld: skipping incompatible /work/install/gcc_x64/lib/gcc/x86_64-linux-gnu/8.0.0/libgcc.a when searching for -lgcc
/work/install/binutils_x64/x86_64-linux-gnu/bin/ld: cannot find -lgcc
So it doesn't seem to be able to find a 32-bit libgcc although that GCC
supports -m32...
Wilco
On Thu, Sep 14, 2017 at 7:57 AM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> H.J. Lu wrote:
>
>> # CC="gcc -m32 -march=i686" CXX="g++ -m32 -march=i686"
>> /export/gnu/import/git/sources/glibc/configure --prefix=/usr
>> --target=i686-linux --build=i686-linux --host=i686-linux
>> --enable-hardcoded-path-in-tests
>>
>> to configure glibc for i686 on Linux/x86-64. It works fine.
>
> Doing it exactly like that I get:
>
> /work/install/binutils_x64/x86_64-linux-gnu/bin/ld: skipping incompatible /work/install/gcc_x64/lib/gcc/x86_64-linux-gnu/8.0.0/libgcc.a when searching for -lgcc
> /work/install/binutils_x64/x86_64-linux-gnu/bin/ld: cannot find -lgcc
>
> So it doesn't seem to be able to find a 32-bit libgcc although that GCC
> supports -m32...
Please make sure that your GCC has 32-bit libgcc.a:
[hjl@gnu-6 i386]$ gcc -print-libgcc-file-name
/usr/lib/gcc/x86_64-redhat-linux/7/libgcc.a
[hjl@gnu-6 i386]$ gcc -m32 -print-libgcc-file-name
/usr/lib/gcc/x86_64-redhat-linux/7/32/libgcc.a
[hjl@gnu-6 i386]$
On Thu, 14 Sep 2017, Wilco Dijkstra wrote:
> H.J. Lu wrote:
>
> > # CC="gcc -m32 -march=i686" CXX="g++ -m32 -march=i686"
> > /export/gnu/import/git/sources/glibc/configure --prefix=/usr
> > --target=i686-linux --build=i686-linux --host=i686-linux
> > --enable-hardcoded-path-in-tests
> >
> > to configure glibc for i686 on Linux/x86-64. It works fine.
>
> Doing it exactly like that I get:
>
> /work/install/binutils_x64/x86_64-linux-gnu/bin/ld: skipping incompatible /work/install/gcc_x64/lib/gcc/x86_64-linux-gnu/8.0.0/libgcc.a when searching for -lgcc
> /work/install/binutils_x64/x86_64-linux-gnu/bin/ld: cannot find -lgcc
>
> So it doesn't seem to be able to find a 32-bit libgcc although that GCC
> supports -m32...
That suggests you have a --disable-multilib compiler.
You can use build-many-glibcs.py to build an x86_64 compiler that supports
all of -m64, -m32, -mx32 (build-many-glibcs.py <dir> checkout;
build-many-glibcs.py <dir> host-libraries; build-many-glibcs.py <dir>
compilers x86_64-linux-gnu). Having got that compiler (in
<dir>/install/compilers/x86_64-linux-gnu) you can then use it for building
/ testing glibc manually (including running execution tests in such a
build - make sure to copy libstdc++ and libgcc_s shared libraries from the
right multilib to the build directory before running make check) if you
want.
Joseph Myers wrote:
> H.J. Lu wrote:
>
> > # CC="gcc -m32 -march=i686" CXX="g++ -m32 -march=i686"
> > /export/gnu/import/git/sources/glibc/configure --prefix=/usr
> > --target=i686-linux --build=i686-linux --host=i686-linux
> > --enable-hardcoded-path-in-tests
> >
> > to configure glibc for i686 on Linux/x86-64. It works fine.
> That suggests you have a --disable-multilib compiler.
Thanks, I've rebuilt everything and it now works perfectly.
So I can confirm x86 GLIBC unwinding also works as expected after
my patch.
OK for commit?
Wilco
@@ -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.
@@ -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)
@@ -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
@@ -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
@@ -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.
@@ -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
@@ -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)
@@ -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
@@ -5,7 +5,3 @@ endif
ifeq ($(subdir),gmon)
sysdep_routines += _mcount
endif
-
-ifeq ($(subdir),debug)
-CFLAGS-backtrace.c += -funwind-tables
-endif
@@ -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