elf: support dynamic symbol table lookup
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 31 Aug 2018 15:59:56 +0000 (11:59 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 31 Aug 2018 18:41:57 +0000 (14:41 -0400)
commitef3dfe5d31c88fb548189a6441aaf8b2afc0bd4b
tree03b4828050e7feafa5cdb0c9b778a9c5084a30a7
parent5ae0c80e1f9a3ed89044a6e810d7d844fab6ba24
elf: support dynamic symbol table lookup

Background
==========
There may be two symbol tables in a shared object or executable. The
normal symbol table (.symtab) and the dynamic symbol table (.dynsym).

The normal symbol table contains lots of information, such as static
linking data, but none of it is used at runtime. This is why some
shared libraries are 'stripped', reducing the final size of the file.
Stripping an object file removes the entire .symtab section of the elf
file, amongst other things.

The dynamic symbol table contains symbols that are needed for dynamic
linking of the shared object. The symbols in that section form a subset
of the symbols contained in the normal symbol section (before
stripping). The .dynsym section is left untouched when stripping a file
as it is needed at runtime.

Current limitation
==================
The current elf parsing implementation looks for the normal symbol
section (.symtab) to find the target symbol. If the .symtab is not
found, the parsing stops and returns that the symbol was not found. As
explained in the section above, a shared library might be stripped from
its normal symbol table, but still have a dynamic symbol table (.dynsym)
containing the information of the target symbol. For example, on
distributions where libc is stripped, the malloc symbol can only be
found in the .dynsym section

Solution
========
Look for the normal symbol section first and, if it's found, use it to
find the symbol, as was previously done. If the .symtab is absent,
try to use the dynamic symbol section instead.

This commit also adds a testcase for this feature.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/lttng-elf.c
tests/regression/kernel/test_userspace_probe
tests/utils/testapp/userspace-probe-elf-binary/Makefile.am
tests/utils/testapp/userspace-probe-elf-binary/foo.c [new file with mode: 0644]
tests/utils/testapp/userspace-probe-elf-binary/foo.h [new file with mode: 0644]
tests/utils/testapp/userspace-probe-elf-binary/userspace-probe-elf-binary.c
This page took 0.025605 seconds and 4 git commands to generate.