From 567648d9fd3baa584e7b6182d8e0e4870888ae2d Mon Sep 17 00:00:00 2001 From: Yufeng Jin Date: Mon, 30 Oct 2023 19:24:08 +0800 Subject: [PATCH] mcount: Restore/reset rstack only when the return address is hijacked 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 --- libmcount/wrap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libmcount/wrap.c b/libmcount/wrap.c index fd05655b4..30adcf097 100644 --- a/libmcount/wrap.c +++ b/libmcount/wrap.c @@ -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]; @@ -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;