Re: [PATCH perf/core 2/4] perf-probe: Fix to handle aliased symbols in glibc

Namhyung Kim
2015-03-03T13:32:08Z

Hi Masami,

On Mon, Mar 02, 2015 at 09:49:53PM +0900, Masami Hiramatsu wrote:
> Fix perf probe to handle aliased symbols correctly in glibc.
> In the glibc, several symbols are defined as an alias of
> __libc_XXX, e.g. malloc is an alias of __libc_malloc.
> In such cases, dwarf has no subroutine instances of the
> alias functions (e.g. no "malloc" instance), but the map
> has that symbol and its address.
> Thus, if we search the alieased symbol in debuginfo, we
> always fail to find it, but it is in the map.
>
> To solve this problem, this fails back to address-based
> alternative search, which searches the symbol in the map,
> translates its address to alternative (correct) function
> name by using debuginfo, and retry to find the alternative
> function point from debuginfo.
>
> This adds fail-back process to --vars, --lines and --add
> options. So, now you can use those on malloc@libc :)

So this is only for binaries that have debuginfo, right?

I have a similar issue with no debuginfo.

$ perf probe -x /usr/lib/libc.so.6 -V calloc
The /usr/lib/libc-2.21.so file has no debug information.
Rebuild with -g, or install an appropriate debuginfo package.
Error: Failed to show vars.

But it also failed to add a probe to calloc:

$ perf probe -x /usr/lib/libc.so.6 -a calloc
Failed to find symbol calloc in /usr/lib/libc-2.21.so
Error: Failed to add events.

Of course there's calloc in the libc binary.

$ nm /usr/lib/libc.so.6 | grep calloc
000000000007b1f0 t __calloc
000000000007b1f0 T __libc_calloc
000000000007b1f0 W calloc

I think the problem is that calloc is a weak symbol so it'll be
discarded during the symbol loading. It's because to avoid multiple
symbols (or aliases) at a same address so we choose a better symbol
using heuristics. But for this case I think we can allow aliases
since it's used only for finding probe points.

Thanks,
Namhyung