Skip to content

Commit

Permalink
mcount: Restore/reset rstack only when the return address is hijacked
Browse files Browse the repository at this point in the history
When specifying estimate_return, the return address is not hijacked.
This patch ensures that mcount_rstack_reset_exception() is not called
in this case, to avoid recording incorrect end times.

Signed-off-by: Yufeng Jin <jinyufeng2000@gmail.com>
  • Loading branch information
jyf111 authored and namhyung committed Nov 6, 2023
1 parent 3acdd03 commit 567648d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libmcount/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ void mcount_rstack_reset_exception(struct mcount_thread_data *mtdp, unsigned lon
int idx;
struct mcount_ret_stack *rstack;

if (unlikely(mcount_estimate_return))
return;

/* it needs to find how much stack frame unwinds */
for (idx = mtdp->idx - 1; idx >= 0; idx--) {
rstack = &mtdp->rstack[idx];
Expand Down Expand Up @@ -393,7 +396,7 @@ __visible_default void *__cxa_begin_catch(void *exception)
obj = real_cxa_begin_catch(exception);

mtdp = get_thread_data();
if (!mcount_estimate_return && !check_thread_data(mtdp) && unlikely(mtdp->in_exception)) {
if (!check_thread_data(mtdp) && unlikely(mtdp->in_exception)) {
unsigned long *frame_ptr;
unsigned long frame_addr;

Expand Down

0 comments on commit 567648d

Please sign in to comment.