From: Antoine Busque Date: Wed, 13 Apr 2016 21:31:57 +0000 (-0400) Subject: Add is_pic field to statedump soinfo event X-Git-Tag: v2.8.0-rc2~8 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=444da810e491b66b873466c240202c27e0cd1adc;p=lttng-ust.git Add is_pic field to statedump soinfo event This field indicates whether the executable or library is position independent code (PIC). The field is not added to the similar dlopen event from liblttng-ust-dl because in that case all dlopened libraries are necessarily PIC. This allows a posteriori analyses to be performed without having to read the executable file to know whether adresses are relative to the base address or absolute. Signed-off-by: Antoine Busque Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/man/lttng-ust.3.txt b/doc/man/lttng-ust.3.txt index 1f4d7e48..c7b82c1a 100644 --- a/doc/man/lttng-ust.3.txt +++ b/doc/man/lttng-ust.3.txt @@ -777,18 +777,20 @@ This event has no fields. This event has no fields. `lttng_ust_statedump:soinfo`:: - Emitted when information about a currently loaded shared object is - found. + Emitted when information about a currently loaded executable or + shared object is found. + Fields: + [options="header"] -|============================================================== +|================================================================== | Field name | Description -| `baddr` | Base address of loaded library -| `memsz` | Size of loaded library in memory -| `sopath` | Path to loaded library file -|============================================================== +| `baddr` | Base address of loaded executable +| `memsz` | Size of loaded executable in memory +| `sopath` | Path to loaded executable file +| `is_pic` | Whether the executable is + position-independent code +|================================================================== `lttng_ust_statedump:build_id`:: Emitted when a build ID is found in a currently loaded shared diff --git a/include/lttng/ust-elf.h b/include/lttng/ust-elf.h index 6e9d9951..e9b0ac7b 100644 --- a/include/lttng/ust-elf.h +++ b/include/lttng/ust-elf.h @@ -219,6 +219,7 @@ int is_elf_native_endian(struct lttng_ust_elf *elf) struct lttng_ust_elf *lttng_ust_elf_create(const char *path); void lttng_ust_elf_destroy(struct lttng_ust_elf *elf); +uint8_t lttng_ust_elf_is_pic(struct lttng_ust_elf *elf); int lttng_ust_elf_get_memsz(struct lttng_ust_elf *elf, uint64_t *memsz); int lttng_ust_elf_get_build_id(struct lttng_ust_elf *elf, uint8_t **build_id, size_t *length, int *found); diff --git a/liblttng-ust/lttng-ust-elf.c b/liblttng-ust/lttng-ust-elf.c index e9062690..34654558 100644 --- a/liblttng-ust/lttng-ust-elf.c +++ b/liblttng-ust/lttng-ust-elf.c @@ -316,6 +316,18 @@ error: return NULL; } +/* + * Test whether the ELF file is position independent code (PIC) + */ +uint8_t lttng_ust_elf_is_pic(struct lttng_ust_elf *elf) +{ + /* + * PIC has and e_type value of ET_DYN, see ELF specification + * version 1.1 p. 1-3. + */ + return elf->ehdr->e_type == ET_DYN; +} + /* * Destroy the given lttng_ust_elf instance. */ diff --git a/liblttng-ust/lttng-ust-statedump-provider.h b/liblttng-ust/lttng-ust-statedump-provider.h index 5e212d9e..427ba271 100644 --- a/liblttng-ust/lttng-ust-statedump-provider.h +++ b/liblttng-ust/lttng-ust-statedump-provider.h @@ -48,12 +48,14 @@ TRACEPOINT_EVENT(lttng_ust_statedump, soinfo, struct lttng_session *, session, void *, baddr, const char*, sopath, - uint64_t, memsz + uint64_t, memsz, + uint8_t, is_pic ), TP_FIELDS( ctf_integer_hex(void *, baddr, baddr) ctf_integer(uint64_t, memsz, memsz) ctf_string(sopath, sopath) + ctf_integer(uint8_t, is_pic, is_pic) ) ) diff --git a/liblttng-ust/lttng-ust-statedump.c b/liblttng-ust/lttng-ust-statedump.c index 93a035b3..b160e197 100644 --- a/liblttng-ust/lttng-ust-statedump.c +++ b/liblttng-ust/lttng-ust-statedump.c @@ -52,6 +52,7 @@ struct soinfo_data { size_t build_id_len; int vdso; uint32_t crc; + uint8_t is_pic; }; typedef void (*tracepoint_cb)(struct lttng_session *session, void *priv); @@ -84,7 +85,7 @@ void trace_soinfo_cb(struct lttng_session *session, void *priv) tracepoint(lttng_ust_statedump, soinfo, session, so_data->base_addr_ptr, - so_data->resolved_path, so_data->memsz); + so_data->resolved_path, so_data->memsz, so_data->is_pic); } static @@ -147,6 +148,8 @@ int get_elf_info(struct soinfo_data *so_data, int *has_build_id, goto end; } + so_data->is_pic = lttng_ust_elf_is_pic(elf); + end: lttng_ust_elf_destroy(elf); return ret;