Skip to content

Commit

Permalink
Merge branch 'libmcount-update'
Browse files Browse the repository at this point in the history
Two small updates in libmcount during debug #1835:

 * update debug message for clear PLT index understanding
 * ignore unpaired __cyg_profile_func_exit()

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Oct 30, 2023
2 parents f962a2c + a9e8782 commit d36ff37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
18 changes: 16 additions & 2 deletions libmcount/mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,11 @@ static int __cygprof_entry(unsigned long parent, unsigned long child)

if (filtered == FILTER_IN) {
rstack->start_time = mcount_gettime();
rstack->flags = 0;
rstack->flags = MCOUNT_FL_CYGPROF;
}
else {
rstack->start_time = 0;
rstack->flags = MCOUNT_FL_NORECORD;
rstack->flags = MCOUNT_FL_CYGPROF | MCOUNT_FL_NORECORD;
}

mcount_entry_filter_record(mtdp, rstack, &tr, NULL);
Expand All @@ -1560,6 +1560,11 @@ static int cygprof_entry(unsigned long parent, unsigned long child)
return ret;
}

static void warn_unpaired_cygprof(void)
{
pr_warn("unpaired cygprof exit: dropping...\n");
}

static void __cygprof_exit(unsigned long parent, unsigned long child)
{
struct mcount_thread_data *mtdp;
Expand All @@ -1582,6 +1587,15 @@ static void __cygprof_exit(unsigned long parent, unsigned long child)

rstack = &mtdp->rstack[mtdp->idx - 1];

/* discard unpaired cygprof exit (due to compiler bug?) */
if (unlikely(!(rstack->flags & MCOUNT_FL_CYGPROF))) {
static pthread_once_t warn_once = PTHREAD_ONCE_INIT;

pthread_once(&warn_once, warn_unpaired_cygprof);
mcount_unguard_recursion(mtdp);
return;
}

if (!(rstack->flags & MCOUNT_FL_NORECORD))
rstack->end_time = mcount_gettime();

Expand Down
1 change: 1 addition & 0 deletions libmcount/mcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum mcount_rstack_flag {
MCOUNT_FL_ARGUMENT = (1U << 11),
MCOUNT_FL_READ = (1U << 12),
MCOUNT_FL_CALLER = (1U << 13),
MCOUNT_FL_CYGPROF = (1U << 14),
};

struct plthook_data;
Expand Down
4 changes: 2 additions & 2 deletions libmcount/plthook.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void restore_plt_functions(struct plthook_data *pd)
continue;

overwrite_pltgot(pd, got_idx, skip_sym->addr);
pr_dbg2("overwrite GOT[%d] to %p (%s)\n", got_idx, skip_sym->addr,
pr_dbg2("overwrite GOT[%d + 3] to %p (%s)\n", i, skip_sym->addr,
skip_sym->name);

skipped = true;
Expand All @@ -171,7 +171,7 @@ static void restore_plt_functions(struct plthook_data *pd)
continue;

symname = demangle(sym->name);
pr_dbg2("restore GOT[%d] from \"%s\"(%#lx) to PLT(base + %#lx)\n", got_idx,
pr_dbg2("restore GOT[%d + 3] from \"%s\"(%#lx) to PLT(base + %#lx)\n", i,
symname, resolved_addr, plthook_addr - pd->base_addr);
free(symname);
}
Expand Down

0 comments on commit d36ff37

Please sign in to comment.