From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0790E3858D28; Wed, 9 Feb 2022 12:34:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0790E3858D28 From: "matti.niemenmaa+gccbugs at iki dot fi" To: gcc-bugs@gcc.gnu.org Subject: [Bug libbacktrace/104463] New: Split debug info not loaded from .debug/ if .gnu_debuglink points to binary itself Date: Wed, 09 Feb 2022 12:34:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libbacktrace X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: matti.niemenmaa+gccbugs at iki dot fi X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Feb 2022 12:34:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104463 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 int main(void) { int x =3D INT_MAX; return x + 1; } With normal (non-split) debug info, no problem: $ gcc -o bug bug.c -ggdb3 -fsanitize=3Dundefined $ UBSAN_OPTIONS=3Dprint_stacktrace=3D1 ./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=3Dundefined $ ( rm -rf .debug && mkdir .debug && \ cd .debug && \ objcopy --only-keep-debug ../bug bug.dbg && \ objcopy --strip-debug ../bug && \ objcopy --add-gnu-debuglink=3Dbug.dbg ../bug ) $ UBSAN_OPTIONS=3Dprint_stacktrace=3D1 ./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 mai= n: $ gcc -o bug bug.c -ggdb3 -fsanitize=3Dundefined $ ( rm -rf .debug && mkdir .debug && \ cd .debug && \ objcopy --only-keep-debug ../bug bug && \ objcopy --strip-debug ../bug && \ objcopy --add-gnu-debuglink=3Dbug ../bug ) $ UBSAN_OPTIONS=3Dprint_stacktrace=3D1 ./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 cas= e: $ gdb -q ./bug 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 follo= wing 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=3Dgcc-11 COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 11.1.0-1ubuntu1~20.04' --with-bugurl=3Dfile:///usr/share/doc/gcc-11/README.= Bugs --enable-languages=3Dc,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix= =3D/usr --with-gcc-major-version-only --program-suffix=3D-11 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-bootstrap --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-= zlib --enable-libphobos-checking=3Drelease --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --disable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-11-2V7zgg/gcc-11-11.1.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-11-2V7zgg/gcc-11-11.1.0/deb= ian/tmp-gcn/usr --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linux-gnu --with-build-config=3Dbootstrap-lto-lean --enable-link-serialization=3D2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04)=