Support split debug symbols without build-id (gentoo-style)
Under Gentoo distribution (Linux), if a library is built with splitdebug feature where debug symbols are splited from the elf binaries into one specific location under /usr/lib/debug directory. However, somehow the tool used to split debug symbols only creates debuglink without introducing build-id. It is different from Debian-style and Fedora-style. Could we add support loading symbols from debuglink?
Both of gdb and lldb can load symbols from debuglink without extra setups.
(gdb) b main
Breakpoint 1 at 0xd81d7: file /home/hky/yass/src/cli/cli.cpp, line 37.
(gdb) r
Starting program: /home/hky/yass/build-release/yass_cli
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Breakpoint 1, main (argc=1, argv=0x7fffffffd948) at /home/hky/yass/src/cli/cli.cpp:37
37 if (!SetUTF8Locale()) {
(gdb) info shared
From To Syms Read Shared Object Library
0x00007ffff7fcb060 0x00007ffff7ff00c1 Yes /lib64/ld-linux-x86-64.so.2
0x00007ffff7ee11f0 0x00007ffff7f4fb69 Yes /lib64/libm.so.6
0x00007ffff7eb7330 0x00007ffff7ecccdd Yes /usr/lib/gcc/x86_64-pc-linux-gnu/12/libgcc_s.so.1
0x00007ffff7d03380 0x00007ffff7e52bc9 Yes /lib64/libc.so.6
Split debug files are located at /usr/lib/debug directory (at least, gentoo).
➜ ~ find /usr/lib/debug -name "libc.so.6*"
/usr/lib/debug/lib64/libc.so.6.debug
/usr/lib/debug/lib/libc.so.6.debug
Using llvm-readobj to dump debuglink section:
➜ build-release git:(develop) llvm-readobj --sections --section-data /lib64/libc.so.6|grep -A 15 gnu_debuglink
Name: .gnu_debuglink (1031)
Type: SHT_PROGBITS (0x1)
Flags [ (0x0)
]
Address: 0x0
Offset: 0x1CAFF4
Size: 20
Link: 0
Info: 0
AddressAlignment: 4
EntrySize: 0
SectionData (
0000: 6C696263 2E736F2E 362E6465 62756700 |libc.so.6.debug.|
0010: 74B07A00 |t.z.|
)
}
Errors showed by orbit in the same machine:
Could not load debug symbols for "/lib64/libc.so.6": Failed to find symbols for module "/lib64/libc.so.6" with build_id="":
- Unable to find local symbols for module "/lib64/libc.so.6": build id is empty.
- Not able to search for symbols on the instance.
Also: Could not load fallback symbols for "/lib64/libc.so.6":
* Could not find module file itself in cache: Unable to find object file in cache for module "/lib64/libc.so.6"
* Could not find module file itself locally.
* Could not search for module file itself on the instance.
Using readelf tool, it shows there is no build-id section:
➜ build-release git:(develop) readelf -n /lib64/libc.so.6
Displaying notes found in: .note.gnu.property
Owner Data size Description
GNU 0x00000020 NT_GNU_PROPERTY_TYPE_0
Properties: x86 feature used: x86, x87, XMM, YMM, ZMM, MASK
x86 ISA used: x86-64-baseline, x86-64-v2, x86-64-v3, x86-64-v4
Displaying notes found in: .note.ABI-tag
Owner Data size Description
GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
OS: Linux, ABI: 3.2.0
It shows /usr/lib/debug is a hard coded path in lldb (debugger)'s source code lldb/source/Symbol/LocateSymbolFile.cpp
// Add /usr/lib/debug directory.
{
FileSpec file_spec("/usr/lib/debug");
FileSystem::Instance().Resolve(file_spec);
debug_file_search_paths.AppendIfUnique(file_spec);
}