public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libbacktrace/104463] New: Split debug info not loaded from .debug/ if .gnu_debuglink points to binary itself
@ 2022-02-09 12:34 matti.niemenmaa+gccbugs at iki dot fi
2022-02-25 12:39 ` [Bug libbacktrace/104463] " mark at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: matti.niemenmaa+gccbugs at iki dot fi @ 2022-02-09 12:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104463
Bug ID: 104463
Summary: Split debug info not loaded from .debug/ if
.gnu_debuglink points to binary itself
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libbacktrace
Assignee: unassigned at gcc dot gnu.org
Reporter: matti.niemenmaa+gccbugs at iki dot fi
CC: ian at gcc dot gnu.org
Target Milestone: ---
(Related to PR77631; it seems this issue has been there since the initial
implementation.)
Some example code triggering UBSan just to get a stack trace:
$ cat bug.c
#include <limits.h>
int main(void) {
int x = INT_MAX;
return x + 1;
}
With normal (non-split) debug info, no problem:
$ gcc -o bug bug.c -ggdb3 -fsanitize=undefined
$ UBSAN_OPTIONS=print_stacktrace=1 ./bug
bug.c:4:14: runtime error: signed integer overflow: 2147483647 + 1 cannot be
represented in type 'int'
#0 0x55d52e60e182 in main /path/to/bug.c:4
#1 0x7fccca3fb0b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#2 0x55d52e60e08d in _start (/path/to/bug+0x108d)
With debug info split into a different filename in .debug, no problem:
$ gcc -o bug bug.c -ggdb3 -fsanitize=undefined
$ ( rm -rf .debug && mkdir .debug && \
cd .debug && \
objcopy --only-keep-debug ../bug bug.dbg && \
objcopy --strip-debug ../bug && \
objcopy --add-gnu-debuglink=bug.dbg ../bug )
$ UBSAN_OPTIONS=print_stacktrace=1 ./bug
bug.c:4:14: runtime error: signed integer overflow: 2147483647 + 1 cannot be
represented in type 'int'
#0 0x55d52e60e182 in main /path/to/bug.c:4
#1 0x7fccca3fb0b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#2 0x55d52e60e08d in _start (/path/to/bug+0x108d)
But when using the same filename, we lose the file/line number info for main:
$ gcc -o bug bug.c -ggdb3 -fsanitize=undefined
$ ( rm -rf .debug && mkdir .debug && \
cd .debug && \
objcopy --only-keep-debug ../bug bug && \
objcopy --strip-debug ../bug && \
objcopy --add-gnu-debuglink=bug ../bug )
$ UBSAN_OPTIONS=print_stacktrace=1 ./bug
bug.c:4:14: runtime error: signed integer overflow: 2147483647 + 1 cannot be
represented in type 'int'
#0 0x55cbd7c4117f in main (/path/to/bug+0x117f)
#1 0x7f863518c0b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#2 0x55cbd7c4108d in _start (/path/to/bug+0x108d)
And e.g. strace can verify that it never even looks at the file in .debug/.
gdb, on the other hand, does load the debug info correctly even in this case:
$ gdb -q ./bug </dev/null
Reading symbols from ./bug...
Reading symbols from /path/to/.debug/bug...
(gdb) quit
In my "real world" case all shared libraries on the system are built like this,
for example libubsan itself:
$ ls -l /usr/lib/{.debug/,}libubsan* | cut -d/ -f2-
usr/lib/.debug/libubsan.so.1.0.0
usr/lib/libubsan.so.1 -> libubsan.so.1.0.0
usr/lib/libubsan.so.1.0.0
$ readelf -p .gnu_debuglink /usr/lib/libubsan.so.1
String dump of section '.gnu_debuglink':
[ 0] libubsan.so.1.0.0
[ 16] n
I'm not sure what the most appropriate fix is, but perhaps one of the following
would make sense:
- if the .gnu_debuglink points to the file itself, ignore it and only look in
.debug/
- if the .gnu_debuglink points to the file itself, prefer a .debug/ file to it
- if the .gnu_debuglink pointee is successfully loaded but contains no debug
info, continue searching in .debug/
I haven't checked what gdb itself does.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
11.1.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --disable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04)
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug libbacktrace/104463] Split debug info not loaded from .debug/ if .gnu_debuglink points to binary itself
2022-02-09 12:34 [Bug libbacktrace/104463] New: Split debug info not loaded from .debug/ if .gnu_debuglink points to binary itself matti.niemenmaa+gccbugs at iki dot fi
@ 2022-02-25 12:39 ` mark at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: mark at gcc dot gnu.org @ 2022-02-25 12:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104463
Mark Wielaard <mark at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2022-02-25
--- Comment #1 from Mark Wielaard <mark at gcc dot gnu.org> ---
Note. The term "split dwarf" is often associated with the -gsplit-dwarf option,
which uses .dwo sections (and files) to split DWARF debuginfo. This bug isn't
about that.
I can replicate the issue, but haven't fully traced why it happens.
It seems libbacktrace gets confused about where /proc/self/exe points to and
tries to open /proc/self/bug, /proc/self/.debug/bug and
/usr/lib/debug//proc/self/bug
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-25 12:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 12:34 [Bug libbacktrace/104463] New: Split debug info not loaded from .debug/ if .gnu_debuglink points to binary itself matti.niemenmaa+gccbugs at iki dot fi
2022-02-25 12:39 ` [Bug libbacktrace/104463] " mark at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).