Skip to content

Commit df606c6

Browse files
pavel-orekhovPavel Orekhov
authored andcommitted
[PATCH] fix symbol search loop at debuglink mode
Some distribs like ubuntu'18 creatively name files with debug symbols. (same name without .debug suffix). And give no `build-id` way. $dpkg -L libc6-dbg | grep -v gconv /usr/lib/debug/.build-id/68/f36706eb2e6eee4046c4fdca2a19540b2f6113.debug /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so $ dpkg -L libc6 /lib/x86_64-linux-gnu/libc-2.27.so /lib/x86_64-linux-gnu/libc.so.6 $ objdump -s -j .gnu_debuglink -j .note.gnu.build-id \ /lib/x86_64-linux-gnu/libc-2.27.so Contents of section .gnu_debuglink: 0000 6c696263 2d322e32 372e736f 00000000 libc-2.27.so.... 0010 5ac51387 Z... Contents of section .note.gnu.build-id: 0270 04000000 14000000 03000000 474e5500 ............GNU. 0280 ce450eb0 1a5e5acc 7ce7b8c2 633b02cc .E...^Z.|...c;.. 0290 1093339e ..3. So elf_find_debugfile_by_debuglink("libc") loops back to /lib/x86_64-linux-gnu/libc-2.27.so and can't lookup symbols for libc and another standard libs. This patch breaks this loop and allows to lookup for symbols at other places.
1 parent 4f57c99 commit df606c6

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

elf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ static int
917917
elf_try_debugfile (struct backtrace_state *state, const char *prefix,
918918
size_t prefix_len, const char *prefix2, size_t prefix2_len,
919919
const char *debuglink_name,
920+
const char *ref_filename,
920921
backtrace_error_callback error_callback, void *data)
921922
{
922923
size_t debuglink_len;
@@ -936,6 +937,9 @@ elf_try_debugfile (struct backtrace_state *state, const char *prefix,
936937
memcpy (try + prefix_len + prefix2_len, debuglink_name, debuglink_len);
937938
try[prefix_len + prefix2_len + debuglink_len] = '\0';
938939

940+
if(ref_filename && *ref_filename && !strcmp(try, ref_filename))
941+
return -1; // loop detected
942+
939943
ret = backtrace_open (try, error_callback, data, &does_not_exist);
940944

941945
backtrace_free (state, try, try_len, error_callback, data);
@@ -1026,7 +1030,8 @@ elf_find_debugfile_by_debuglink (struct backtrace_state *state,
10261030
}
10271031

10281032
ddescriptor = elf_try_debugfile (state, prefix, prefix_len, "", 0,
1029-
debuglink_name, error_callback, data);
1033+
debuglink_name, filename,
1034+
error_callback, data);
10301035
if (ddescriptor >= 0)
10311036
{
10321037
ret = ddescriptor;
@@ -1037,7 +1042,7 @@ elf_find_debugfile_by_debuglink (struct backtrace_state *state,
10371042

10381043
ddescriptor = elf_try_debugfile (state, prefix, prefix_len, ".debug/",
10391044
strlen (".debug/"), debuglink_name,
1040-
error_callback, data);
1045+
filename, error_callback, data);
10411046
if (ddescriptor >= 0)
10421047
{
10431048
ret = ddescriptor;
@@ -1049,7 +1054,7 @@ elf_find_debugfile_by_debuglink (struct backtrace_state *state,
10491054
ddescriptor = elf_try_debugfile (state, "/usr/lib/debug/",
10501055
strlen ("/usr/lib/debug/"), prefix,
10511056
prefix_len, debuglink_name,
1052-
error_callback, data);
1057+
filename, error_callback, data);
10531058
if (ddescriptor >= 0)
10541059
ret = ddescriptor;
10551060

0 commit comments

Comments
 (0)