Skip to content

Commit

Permalink
mcount: Check filename when dlopen libraries
Browse files Browse the repository at this point in the history
It may load other dependent libraries as well, but we only care about
the one it loads with dlopen().

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Nov 30, 2024
1 parent b4a8c4b commit 05045a0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libmcount/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
extern struct uftrace_sym_info mcount_sym_info;

struct dlopen_base_data {
const char *filename;
struct mcount_thread_data *mtdp;
uint64_t timestamp;
};
Expand Down Expand Up @@ -77,6 +78,8 @@ static int dlopen_base_callback(struct dl_phdr_info *info, size_t size, void *ar
return 0;
if (!strcmp("linux-vdso.so.1", info->dlpi_name))
return 0;
if (!strstr(info->dlpi_name, data->filename))
return 0;

p = realpath(info->dlpi_name, buf);
if (p == NULL)
Expand Down Expand Up @@ -465,6 +468,7 @@ __visible_default void *dlopen(const char *filename, int flags)
struct mcount_thread_data *mtdp;
struct dlopen_base_data data = {
.timestamp = mcount_gettime(),
.filename = filename,
};
void *ret;

Expand Down

0 comments on commit 05045a0

Please sign in to comment.