Discussion:
gcc-4.8 and libbacktrace
Ryan Johnson
2013-05-27 14:11:07 UTC
Permalink
Hi all,

FYI, gcc-4.8 includes a new libbacktrace.a (BSD-licensed, I believe)
that uses dwarf unwind info to accurately unwind the stack. It's thread
safe, doesn't call malloc, and works properly from signal handlers. GCC
uses it internally to generate its own backtraces on ICE, and go/fortran
use it to generate their backtraces. The library itself is virtually
stand-alone other than a few stray header files from the gcc sources
(according to its developers). I've confirmed (on linux) that the
libbacktrace.a compiled as part of gcc-4.8 works fine when linked
against code generated by gcc-4.6, for example. The only small annoyance
is that libbacktrace doesn't get installed with gcc, so you have to
dredge it out of the build dir yourself.

At some point there was concern about unwind tables bloating the
executable, but IIRC the x86_64 ABI requires them anyway, so 64-bit
cygwin won't see any difference (iirc, the tables were only a few
hundreds of kB last time I checked 32-bit cygwin).

(I realize that SHTDI, and that somebody won't be me... just wanted to
throw the idea out there in case anybody feels an itch)

Caveat #1: Technically, libbacktrace is ELF-only, so it might take a
touch of fiddling to teach it about cygwin's object format. I had the
impression that cygwin object files are basically ELF in disguise,
though, so it shouldn't be hard to close the gap.

Caveat #2: the library caches all debug info of all loaded objects the
first time it's called, which could bloat the runtime image and also
misses dlopen/dlclose calls that arrive afterward. It might be possible
to disable caching for one-off uses, though (or cygwin1.dll could just
tweak its dlopen/dlclose to invalidate caches).

Thoughts?
Ryan
Corinna Vinschen
2013-05-27 14:22:32 UTC
Permalink
Post by Ryan Johnson
Hi all,
FYI, gcc-4.8 includes a new libbacktrace.a (BSD-licensed, I believe)
that uses dwarf unwind info to accurately unwind the stack. It's
thread safe, doesn't call malloc, and works properly from signal
handlers. GCC uses it internally to generate its own backtraces on
ICE, and go/fortran use it to generate their backtraces. The library
itself is virtually stand-alone other than a few stray header files
from the gcc sources (according to its developers). I've confirmed
(on linux) that the libbacktrace.a compiled as part of gcc-4.8 works
fine when linked against code generated by gcc-4.6, for example. The
only small annoyance is that libbacktrace doesn't get installed with
gcc, so you have to dredge it out of the build dir yourself.
At some point there was concern about unwind tables bloating the
executable, but IIRC the x86_64 ABI requires them anyway, so 64-bit
cygwin won't see any difference (iirc, the tables were only a few
hundreds of kB last time I checked 32-bit cygwin).
(I realize that SHTDI, and that somebody won't be me... just wanted
to throw the idea out there in case anybody feels an itch)
Caveat #1: Technically, libbacktrace is ELF-only, so it might take a
touch of fiddling to teach it about cygwin's object format. I had
the impression that cygwin object files are basically ELF in
disguise, though, so it shouldn't be hard to close the gap.
Dunno where you got this impression. Cygwin executables are PE/COFF,
as all executables on Windows. They contain dwarf-2 debug info
Post by Ryan Johnson
Caveat #2: the library caches all debug info of all loaded objects
the first time it's called, which could bloat the runtime image and
also misses dlopen/dlclose calls that arrive afterward. It might be
possible to disable caching for one-off uses, though (or cygwin1.dll
could just tweak its dlopen/dlclose to invalidate caches).
Thoughts?
No, since you didn't say what you expect. What is the end result you're
looking for, a libbacktrace package (Yes, SHTDI), or integration of the
backtrace stuff into Cygwin? If the latter, that's impossible due to
licensing reasons.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Ryan Johnson
2013-05-27 14:45:13 UTC
Permalink
Post by Corinna Vinschen
Post by Ryan Johnson
Hi all,
FYI, gcc-4.8 includes a new libbacktrace.a (BSD-licensed, I believe)
that uses dwarf unwind info to accurately unwind the stack.
Thoughts?
No, since you didn't say what you expect. What is the end result you're
looking for, a libbacktrace package (Yes, SHTDI), or integration of the
backtrace stuff into Cygwin? If the latter, that's impossible due to
licensing reasons.
The latter, so I guess it's a non-starter.

Out of curiosity, what aspect of the library's BSD license allows gcc to
use it but not cygwin?

Ryan
Corinna Vinschen
2013-05-27 15:03:05 UTC
Permalink
Post by Ryan Johnson
Post by Corinna Vinschen
Post by Ryan Johnson
Hi all,
FYI, gcc-4.8 includes a new libbacktrace.a (BSD-licensed, I believe)
that uses dwarf unwind info to accurately unwind the stack.
Thoughts?
No, since you didn't say what you expect. What is the end result you're
looking for, a libbacktrace package (Yes, SHTDI), or integration of the
backtrace stuff into Cygwin? If the latter, that's impossible due to
licensing reasons.
The latter, so I guess it's a non-starter.
Out of curiosity, what aspect of the library's BSD license allows
gcc to use it but not cygwin?
Oh, BSD. When I finished reading your email I had already forgotton,
so I assumed GPLv3+.

So, well, still, SHTDI (not me). I'm just wondering if it's really
worth it. For a normal backtrace we have the stackdump file, which is
acurate most of the time, for dwarf2-based backtraces you typically run
the executable under GDB. And then, you need the debuginfo package as
well for this kind of debugging on distro packages.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Ryan Johnson
2013-05-27 15:07:21 UTC
Permalink
Post by Corinna Vinschen
Post by Ryan Johnson
Post by Corinna Vinschen
Post by Ryan Johnson
Hi all,
FYI, gcc-4.8 includes a new libbacktrace.a (BSD-licensed, I believe)
that uses dwarf unwind info to accurately unwind the stack.
Thoughts?
No, since you didn't say what you expect. What is the end result you're
looking for, a libbacktrace package (Yes, SHTDI), or integration of the
backtrace stuff into Cygwin? If the latter, that's impossible due to
licensing reasons.
The latter, so I guess it's a non-starter.
Out of curiosity, what aspect of the library's BSD license allows
gcc to use it but not cygwin?
Oh, BSD. When I finished reading your email I had already forgotton,
so I assumed GPLv3+.
So, well, still, SHTDI (not me). I'm just wondering if it's really
worth it. For a normal backtrace we have the stackdump file, which is
acurate most of the time, for dwarf2-based backtraces you typically run
the executable under GDB. And then, you need the debuginfo package as
well for this kind of debugging on distro packages.
Good point. Come to think of it, the already-available <unwind.h>
functionality supplied by gcc gives most of the benefit (accurate,
robust unwinding even when frame pointer was omitted, etc.). That would
be easier to integrate, too, if it's not already there.

Ryan

Loading...