Project

General

Profile

Actions

Feature #474

closed

Make lttng-ust aware of shared object base addresses

Added by Paul Woegerer about 11 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Normal
Target version:
Start date:
03/14/2013
Due date:
% Done:

0%

Estimated time:

Description

Using the glibc function dl_iterate_phdr we are able to iterate the currently opened shared objects from within the traced exe.

This allows us to resolve:

  • Tracepoint call site address to specific line number in the sources (if the tp was emitted from a shared object).
  • Compute the absolute vaddress to install uprobes in shared objects.

To also record any changes of the currently opened shared objects during the application runtime we could use the existing ld-audit interface.
(we would need to implement the hooks la_objopen() and la_objclose() to keep informed about shared object loading and unloading)

References:
man dl_iterate_phdr
man rtld-audit


Files

base_address_recording_prototype.pdf (28.6 KB) base_address_recording_prototype.pdf Paul Woegerer, 09/16/2013 10:44 AM
Actions #1

Updated by Paul Woegerer about 11 years ago

The following code snipped can be used to dump base address info for all shared objects currently loaded:

#define _GNU_SOURCE
#include <link.h>

static int
_dl_iterate_write_memregion( struct dl_phdr_info *info, size_t size, void *data ) {
int j;
for( j = 0; j < info->dlpi_phnum; j++ ) {
if( info->dlpi_phdr[j].p_type == PT_LOAD ) {
uintptr_t base_addr_ptr = info->dlpi_addr + info->dlpi_phdr[j].p_vaddr;
const char* shared_object_name = info->dlpi_name;

// TBD Begin - Emit event with base_addr_ptr and shared_object_name here
// TBD End
break;
}
}
return 0;
}

void
iterate_shared_objects_state() {
dl_iterate_phdr( _dl_iterate_write_memregion, NULL );
}

Actions #2

Updated by Paul Woegerer about 11 years ago

#define _GNU_SOURCE
#include <link.h>

static int
_dl_iterate_write_memregion( struct dl_phdr_info *info, size_t size, void *data )
{
    int j;
    for( j = 0; j < info->dlpi_phnum; j++ )
    {
        if( info->dlpi_phdr[j].p_type == PT_LOAD )
        {
            uintptr_t base_addr_ptr = info->dlpi_addr + info->dlpi_phdr[j].p_vaddr;
            const char* shared_object_name = info->dlpi_name;

            // TBD Begin - Emit event with base_addr_ptr and shared_object_name here

            // TBD End
            break;
        }
    }
    return 0;
}

void
iterate_shared_objects_state()
{
    dl_iterate_phdr( _dl_iterate_write_memregion, NULL );
}
Actions #3

Updated by Paul Woegerer over 10 years ago

Provided prototype implementation, detailed explanation and sample traces:
http://lists.lttng.org/pipermail/lttng-dev/2013-August/021264.html

Currently waiting for review.

Actions #4

Updated by Paul Woegerer over 10 years ago

Added pdf document that explains the prototype implementation in simple terms.

Actions #5

Updated by Paul Woegerer over 10 years ago

We decided to reimplemented the hooks for the dlopen/dlclose usecase with an LD_PRELOAD approach (instead of modifying lttng/tracepoint.h)
Reasons are:
  • Not compatible with the upcoming dynamic instrumentation usecase (here the argument with including a tp header file does not hold anymore)
  • We don't want to introduce hooks specific to tracepoints into something that should be instrumentation-agnostic

I will provide an updated prototype ASOP.

Actions #6

Updated by Mathieu Desnoyers over 8 years ago

  • Target version set to 2.8

We have updated this feature, see:

commit 405be6583fc840d2ad298516edb267281bc2c4dc
Author: Mathieu Desnoyers <>
Date: Mon Aug 31 16:50:50 2015 -0400

baddr statedump: remove dependency on file streams
None of the rest of UST used by applications use file streams (only the
sessiond uses a file streams for metadata). Therefore, use file
descriptors directly for baddr statedump.
Signed-off-by: Mathieu Desnoyers &lt;&gt;

commit d34e6761379227cfd49abb6eab184e1e254ee0b2
Author: Mathieu Desnoyers <>
Date: Mon Aug 31 16:50:03 2015 -0400

baddr statedump: hold ust lock around allocations
Signed-off-by: Mathieu Desnoyers &lt;&gt;

commit 22609c7a82c5c8ebc07c19cade9b4d6ff61bd0d0
Author: Antoine Busque <>
Date: Thu Jul 30 16:37:04 2015 -0400

Add unit tests for lttng_ust_elf
This adds unit tests for UST's ELF parser. Also included are test ELF
files for multiple architectures (x86, x86_64, armeb, aarch64_be). The
procedure to generate these test files is described in
`tests/ust-elf/README.md`.
Signed-off-by: Antoine Busque &lt;&gt;
Signed-off-by: Mathieu Desnoyers &lt;&gt;

commit 8e2aed3f18adc14ec586ef717e396bcac4473dd7
Author: Antoine Busque <>
Date: Thu Jul 2 11:55:53 2015 -0400

Add memory size, build id, and debug link info to statedump and dl
Implement a minimal ELF parser allowing to compute an executable's
in-memory size and to read its build id and debug link info, if any,
at runtime. This is performed during base address statedump, and on
dlopen when using the `liblttng-ust-dl.so` helper.
This adds a `memsz` field to `lttng_ust_statedump:soinfo` and
`lttng_ust_dl:dlopen`. Also adds two events to both providers,
`build_id` and `debug_link`, which are only traced when the
corresponding information is found in the executable file. They can be
matched with the corresponding `soinfo` or `dlopen` via the `baddr`
field shared amongst all the events. Build ID and debug link are
standard methods of identifying and retrieving debug information
corresponding to a specific version of an executable.
The fields `size` and `mtime` from the existing `soinfo` and `dlopen`
events have been removed as they provided no valuable information for
analysis, whereas build ID or debug link allow unambiguous retrieval
of the debug information, and the on-disk `size` is superseded by the
in-memory `memsz`.
Signed-off-by: Antoine Busque &lt;&gt;
Signed-off-by: Mathieu Desnoyers &lt;&gt;
Actions #7

Updated by Mathieu Desnoyers over 8 years ago

  • Status changed from New to Resolved
Actions

Also available in: Atom PDF