Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing symbols in valgrind stacktrace

I'm using valgrind to debug a binary which uses loadable libraries via dlopen. On debian stable the stacktrace does not contain symbols for calls inside the loadable lib.

| | ->11.55% (114,688B) 0x769492C: ???
| | | ->11.55% (114,688B) 0x7697289: ???
| | |   ->11.55% (114,688B) 0x769806F: ???
| | |     ->11.55% (114,688B) 0x419812: myfunc (main.c:1010)

Valgrind on debian unstable works fine and the symbols are properly resolved. So I started looking what is different. I have these packages on both systems (valgrind was updated to 3.7 from unstable):

ii  valgrind                      1:3.7.0-1+b1
ii  libtool                       2.2.6b-2
ii  gcc                           4:4.4.5-1
ii  binutils                      2.20.1-16

The libs are not stripped and contain debuginfo:

 ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x33ffd210859178c15bb3923c5491e1a1b6065015, not stripped

Looking closer I noticed that the size of the libraries are different, on debian unstable the lib is slightly bigger. Comparing them with readelf, the size of the debug info is bigger.

  [26] .debug_aranges    PROGBITS        0000000000000000 00a74c 000090 00      0   0  1
  [27] .debug_pubnames   PROGBITS        0000000000000000 00a7dc 000385 00      0   0  1
  [28] .debug_info       PROGBITS        0000000000000000 00ab61 00512f 00      0   0  1
  [29] .debug_abbrev     PROGBITS        0000000000000000 00fc90 0006e2 00      0   0  1
  [30] .debug_line       PROGBITS        0000000000000000 010372 002314 00      0   0  1
  [31] .debug_str        PROGBITS        0000000000000000 012686 0019d3 01  MS  0   0  1
  [32] .debug_loc        PROGBITS        0000000000000000 014059 000f24 00      0   0  1
  [33] .debug_macinfo    PROGBITS        0000000000000000 014f7d 179082 00      0   0  1
  [34] .debug_ranges     PROGBITS        0000000000000000 18dfff 000060 00      0   0  1

This makes me think that something is missing from the debug info section from the binaries built on debian stable. Now my question is: why and how are the binaries different? The tools (gcc, libtool, binutils) used in the build are the same, including the compiler/linker flags and commands (I checked with diff on make's output).

Update: The debug_info section size difference came from the fact that the full path of the source file is stored there as well and the build home was different. Also there are different openssl versions on unstable/stable which added some different symbols to the debug_info section. Hence the difference in debug_info size.

Running valgrind in debug mode (-d -v -v) shows that it reads symbols from the loadable lib in both cases:

--19837-- Reading syms from /usr/lib/myplugin.so (0x6c62000)
like image 950
b0ti Avatar asked Dec 28 '22 06:12

b0ti


1 Answers

If you are using dlopen for the loadable library, chances are that it was unloaded before the program terminates. Therefore Valgrind is unable to resolve its symbols. Try to avoid calling dlclose on this library. See http://valgrind.org/docs/manual/faq.html#faq.unhelpful for more information.

like image 155
ks1322 Avatar answered Jan 06 '23 05:01

ks1322