[PATCH] perf disasm: Fix off-by-one bug in outside check

Peter Collingbourne posted 1 patch 1 month ago
tools/perf/util/disasm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] perf disasm: Fix off-by-one bug in outside check
Posted by Peter Collingbourne 1 month ago
If a branch target points to one past the end of a function, the branch
should be treated as a branch to another function. This can happen
e.g. with a tail call to a function that is laid out immediately after
the caller.

Link: https://linux-review.googlesource.com/id/Ide471112e82d68177e0faf08ca411d9fcf0a7bdf
Signed-off-by: Peter Collingbourne <pcc@google.com>
---
 tools/perf/util/disasm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index ddcc488f2e5f0..9e0420e14be19 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -384,7 +384,7 @@ static int jump__parse(const struct arch *arch, struct ins_operands *ops, struct
 	start = map__unmap_ip(map, sym->start);
 	end = map__unmap_ip(map, sym->end);
 
-	ops->target.outside = target.addr < start || target.addr > end;
+	ops->target.outside = target.addr < start || target.addr >= end;
 
 	/*
 	 * FIXME: things like this in _cpp_lex_token (gcc's cc1 program):
-- 
2.53.0.473.g4a7958ca14-goog
Re: [PATCH] perf disasm: Fix off-by-one bug in outside check
Posted by Ian Rogers 1 month ago
On Wed, Mar 4, 2026 at 11:06 AM Peter Collingbourne <pcc@google.com> wrote:
>
> If a branch target points to one past the end of a function, the branch
> should be treated as a branch to another function. This can happen
> e.g. with a tail call to a function that is laid out immediately after
> the caller.
>
> Link: https://linux-review.googlesource.com/id/Ide471112e82d68177e0faf08ca411d9fcf0a7bdf
> Signed-off-by: Peter Collingbourne <pcc@google.com>

Fixes:  751b1783da78 ("perf annotate: Mark jumps to outher functions
with the call arrow")
Reviewed-by: Ian Rogers <irogers@google.com>

Thanks!
Ian

> ---
>  tools/perf/util/disasm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
> index ddcc488f2e5f0..9e0420e14be19 100644
> --- a/tools/perf/util/disasm.c
> +++ b/tools/perf/util/disasm.c
> @@ -384,7 +384,7 @@ static int jump__parse(const struct arch *arch, struct ins_operands *ops, struct
>         start = map__unmap_ip(map, sym->start);
>         end = map__unmap_ip(map, sym->end);
>
> -       ops->target.outside = target.addr < start || target.addr > end;
> +       ops->target.outside = target.addr < start || target.addr >= end;
>
>         /*
>          * FIXME: things like this in _cpp_lex_token (gcc's cc1 program):
> --
> 2.53.0.473.g4a7958ca14-goog
>
Re: [PATCH] perf disasm: Fix off-by-one bug in outside check
Posted by Arnaldo Carvalho de Melo 1 month ago
On Wed, Mar 04, 2026 at 11:49:02AM -0800, Ian Rogers wrote:
> On Wed, Mar 4, 2026 at 11:06 AM Peter Collingbourne <pcc@google.com> wrote:
> >
> > If a branch target points to one past the end of a function, the branch
> > should be treated as a branch to another function. This can happen
> > e.g. with a tail call to a function that is laid out immediately after
> > the caller.
> >
> > Link: https://linux-review.googlesource.com/id/Ide471112e82d68177e0faf08ca411d9fcf0a7bdf
> > Signed-off-by: Peter Collingbourne <pcc@google.com>
> 
> Fixes:  751b1783da78 ("perf annotate: Mark jumps to outher functions
> with the call arrow")
> Reviewed-by: Ian Rogers <irogers@google.com>

Thanks, applied to perf-tools, for v7.0.

- Arnaldo
 
> Thanks!
> Ian
> 
> > ---
> >  tools/perf/util/disasm.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
> > index ddcc488f2e5f0..9e0420e14be19 100644
> > --- a/tools/perf/util/disasm.c
> > +++ b/tools/perf/util/disasm.c
> > @@ -384,7 +384,7 @@ static int jump__parse(const struct arch *arch, struct ins_operands *ops, struct
> >         start = map__unmap_ip(map, sym->start);
> >         end = map__unmap_ip(map, sym->end);
> >
> > -       ops->target.outside = target.addr < start || target.addr > end;
> > +       ops->target.outside = target.addr < start || target.addr >= end;
> >
> >         /*
> >          * FIXME: things like this in _cpp_lex_token (gcc's cc1 program):
> > --
> > 2.53.0.473.g4a7958ca14-goog
> >
[PATCH v1] perf annotate loongarch: Fix off-by-one bug in outside check
Posted by Ian Rogers 1 month ago
A copy-paste of an issue fixed by Peter Collingbourne in:
https://lore.kernel.org/linux-perf-users/20260304190613.2507582-1-pcc@google.com/

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/annotate-arch/annotate-loongarch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/perf/util/annotate-arch/annotate-loongarch.c
index 3aeab453a059..950f34e59e5c 100644
--- a/tools/perf/util/annotate-arch/annotate-loongarch.c
+++ b/tools/perf/util/annotate-arch/annotate-loongarch.c
@@ -93,7 +93,7 @@ static int loongarch_jump__parse(const struct arch *arch, struct ins_operands *o
 	start = map__unmap_ip(map, sym->start);
 	end = map__unmap_ip(map, sym->end);
 
-	ops->target.outside = target.addr < start || target.addr > end;
+	ops->target.outside = target.addr < start || target.addr >= end;
 
 	if (maps__find_ams(thread__maps(ms->thread), &target) == 0 &&
 	    map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
-- 
2.53.0.473.g4a7958ca14-goog
Re: [PATCH v1] perf annotate loongarch: Fix off-by-one bug in outside check
Posted by Arnaldo Carvalho de Melo 1 month ago
On Fri, Mar 06, 2026 at 10:53:06AM -0800, Ian Rogers wrote:
> A copy-paste of an issue fixed by Peter Collingbourne in:
> https://lore.kernel.org/linux-perf-users/20260304190613.2507582-1-pcc@google.com/
> 
> Signed-off-by: Ian Rogers <irogers@google.com>

Thanks, applied to perf-tools, for v7.0.

- Arnaldo

> ---
>  tools/perf/util/annotate-arch/annotate-loongarch.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/perf/util/annotate-arch/annotate-loongarch.c
> index 3aeab453a059..950f34e59e5c 100644
> --- a/tools/perf/util/annotate-arch/annotate-loongarch.c
> +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c
> @@ -93,7 +93,7 @@ static int loongarch_jump__parse(const struct arch *arch, struct ins_operands *o
>  	start = map__unmap_ip(map, sym->start);
>  	end = map__unmap_ip(map, sym->end);
>  
> -	ops->target.outside = target.addr < start || target.addr > end;
> +	ops->target.outside = target.addr < start || target.addr >= end;
>  
>  	if (maps__find_ams(thread__maps(ms->thread), &target) == 0 &&
>  	    map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
> -- 
> 2.53.0.473.g4a7958ca14-goog
Re: [PATCH v1] perf annotate loongarch: Fix off-by-one bug in outside check
Posted by Arnaldo Carvalho de Melo 1 month ago
On Fri, Mar 06, 2026 at 10:53:06AM -0800, Ian Rogers wrote:
> A copy-paste of an issue fixed by Peter Collingbourne in:
> https://lore.kernel.org/linux-perf-users/20260304190613.2507582-1-pcc@google.com/

Thanks, applied to perf-tools, for v7.0.

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/annotate-arch/annotate-loongarch.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/perf/util/annotate-arch/annotate-loongarch.c
> index 3aeab453a059..950f34e59e5c 100644
> --- a/tools/perf/util/annotate-arch/annotate-loongarch.c
> +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c
> @@ -93,7 +93,7 @@ static int loongarch_jump__parse(const struct arch *arch, struct ins_operands *o
>  	start = map__unmap_ip(map, sym->start);
>  	end = map__unmap_ip(map, sym->end);
>  
> -	ops->target.outside = target.addr < start || target.addr > end;
> +	ops->target.outside = target.addr < start || target.addr >= end;
>  
>  	if (maps__find_ams(thread__maps(ms->thread), &target) == 0 &&
>  	    map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
> -- 
> 2.53.0.473.g4a7958ca14-goog