linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Some build fixes
@ 2025-03-10 19:45 Arnaldo Carvalho de Melo
  2025-03-10 19:45 ` [PATCH 1/3] libapi: Add missing header with NAME_MAX define to io_dir.h Arnaldo Carvalho de Melo
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-03-10 19:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Hi Namhyung,

	Some fixes I noticed while building with my set of containers.

Best regards,

- Arnaldo

Arnaldo Carvalho de Melo (3):
  libapi: Add missing header with NAME_MAX define to io_dir.h
  perf units: Fix insufficient array space
  perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions

 tools/lib/api/io_dir.h     | 1 +
 tools/perf/ui/stdio/hist.c | 4 ++++
 tools/perf/util/units.c    | 2 +-
 3 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] libapi: Add missing header with NAME_MAX define to io_dir.h
  2025-03-10 19:45 [PATCH 0/3] Some build fixes Arnaldo Carvalho de Melo
@ 2025-03-10 19:45 ` Arnaldo Carvalho de Melo
  2025-03-10 19:45 ` [PATCH 2/3] perf units: Fix insufficient array space Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-03-10 19:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Most systems get this indirectly, but some odd cases (some musl libc
systems) can't find it, so just add the header where NAME_MAX is defined
to avoid that.

Fixes: d118b08f7eee6d6f ("tools lib api: Add io_dir an allocation free readdir alternative")
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/io_dir.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/lib/api/io_dir.h b/tools/lib/api/io_dir.h
index aab73393d2a217ab..ef83e967e48c59f7 100644
--- a/tools/lib/api/io_dir.h
+++ b/tools/lib/api/io_dir.h
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
+#include <linux/limits.h>
 
 #if !defined(SYS_getdents64)
 #if defined(__x86_64__) || defined(__arm__)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] perf units: Fix insufficient array space
  2025-03-10 19:45 [PATCH 0/3] Some build fixes Arnaldo Carvalho de Melo
  2025-03-10 19:45 ` [PATCH 1/3] libapi: Add missing header with NAME_MAX define to io_dir.h Arnaldo Carvalho de Melo
@ 2025-03-10 19:45 ` Arnaldo Carvalho de Melo
  2025-03-10 19:45 ` [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions Arnaldo Carvalho de Melo
  2025-03-13 16:29 ` [PATCH 0/3] Some build fixes Namhyung Kim
  3 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-03-10 19:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <acme@redhat.com>

No need to specify the array size, let the compiler figure that out.

This addresses this compiler warning that was noticed while build
testing on fedora rawhide:

  31    15.81 fedora:rawhide                : FAIL gcc version 15.0.1 20250225 (Red Hat 15.0.1-0) (GCC)
    util/units.c: In function 'unit_number__scnprintf':
    util/units.c:67:24: error: initializer-string for array of 'char' is too long [-Werror=unterminated-string-initialization]
       67 |         char unit[4] = "BKMG";
          |                        ^~~~~~
    cc1: all warnings being treated as errors

Fixes: 9808143ba2e54818 ("perf tools: Add unit_number__scnprintf function")
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/units.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/units.c b/tools/perf/util/units.c
index 32c39cfe209b3bba..4c6a86e1cb54b222 100644
--- a/tools/perf/util/units.c
+++ b/tools/perf/util/units.c
@@ -64,7 +64,7 @@ unsigned long convert_unit(unsigned long value, char *unit)
 
 int unit_number__scnprintf(char *buf, size_t size, u64 n)
 {
-	char unit[4] = "BKMG";
+	char unit[] = "BKMG";
 	int i = 0;
 
 	while (((n / 1024) > 1) && (i < 3)) {
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions
  2025-03-10 19:45 [PATCH 0/3] Some build fixes Arnaldo Carvalho de Melo
  2025-03-10 19:45 ` [PATCH 1/3] libapi: Add missing header with NAME_MAX define to io_dir.h Arnaldo Carvalho de Melo
  2025-03-10 19:45 ` [PATCH 2/3] perf units: Fix insufficient array space Arnaldo Carvalho de Melo
@ 2025-03-10 19:45 ` Arnaldo Carvalho de Melo
  2025-03-10 21:55   ` Namhyung Kim
  2025-03-13 16:29 ` [PATCH 0/3] Some build fixes Namhyung Kim
  3 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-03-10 19:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Do a simple bounds check to avoid this on new gcc versions:

  31    15.81 fedora:rawhide                : FAIL gcc version 15.0.1 20250225 (Red Hat 15.0.1-0) (GCC)
    In function 'callchain__fprintf_left_margin',
        inlined from 'callchain__fprintf_graph.constprop' at ui/stdio/hist.c:246:12:
    ui/stdio/hist.c:27:39: error: iteration 2147483647 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
       27 |         for (i = 0; i < left_margin; i++)
          |                                      ~^~
    ui/stdio/hist.c:27:23: note: within this loop
       27 |         for (i = 0; i < left_margin; i++)
          |                     ~~^~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    --
    util/units.c: In function 'unit_number__scnprintf':
    util/units.c:67:24: error: initializer-string for array of 'char' is too long [-Werror=unterminated-string-initialization]
       67 |         char unit[4] = "BKMG";
          |                        ^~~~~~
    cc1: all warnings being treated as errors

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/stdio/hist.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 74b2c619c56c8ba3..7ac4b98e28bca82e 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <linux/string.h>
@@ -24,6 +25,9 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
 	int i;
 	int ret = fprintf(fp, "            ");
 
+	if (left_margin > USHRT_MAX)
+		left_margin = USHRT_MAX;
+
 	for (i = 0; i < left_margin; i++)
 		ret += fprintf(fp, " ");
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions
  2025-03-10 19:45 ` [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions Arnaldo Carvalho de Melo
@ 2025-03-10 21:55   ` Namhyung Kim
  2025-03-13  7:29     ` Namhyung Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Namhyung Kim @ 2025-03-10 21:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

On Mon, Mar 10, 2025 at 04:45:33PM -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Do a simple bounds check to avoid this on new gcc versions:
> 
>   31    15.81 fedora:rawhide                : FAIL gcc version 15.0.1 20250225 (Red Hat 15.0.1-0) (GCC)
>     In function 'callchain__fprintf_left_margin',
>         inlined from 'callchain__fprintf_graph.constprop' at ui/stdio/hist.c:246:12:
>     ui/stdio/hist.c:27:39: error: iteration 2147483647 invokes undefined behavior [-Werror=aggressive-loop-optimizations]

Hmm.. does it warn about a signed integer overflow?

2147483647 is 0x7fffffff in hex and it should be INT_MAX.
I'm not sure what is the problem.


>        27 |         for (i = 0; i < left_margin; i++)
>           |                                      ~^~
>     ui/stdio/hist.c:27:23: note: within this loop
>        27 |         for (i = 0; i < left_margin; i++)
>           |                     ~~^~~~~~~~~~~~~
>     cc1: all warnings being treated as errors
>     --
>     util/units.c: In function 'unit_number__scnprintf':
>     util/units.c:67:24: error: initializer-string for array of 'char' is too long [-Werror=unterminated-string-initialization]
>        67 |         char unit[4] = "BKMG";
>           |                        ^~~~~~
>     cc1: all warnings being treated as errors

This part belongs to the previous commit. :)

> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: James Clark <james.clark@linaro.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/ui/stdio/hist.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
> index 74b2c619c56c8ba3..7ac4b98e28bca82e 100644
> --- a/tools/perf/ui/stdio/hist.c
> +++ b/tools/perf/ui/stdio/hist.c
> @@ -1,4 +1,5 @@
>  // SPDX-License-Identifier: GPL-2.0
> +#include <limits.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <linux/string.h>
> @@ -24,6 +25,9 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
>  	int i;
>  	int ret = fprintf(fp, "            ");
>  
> +	if (left_margin > USHRT_MAX)
> +		left_margin = USHRT_MAX;
> +
>  	for (i = 0; i < left_margin; i++)
>  		ret += fprintf(fp, " ");
>  
> -- 
> 2.48.1
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions
  2025-03-10 21:55   ` Namhyung Kim
@ 2025-03-13  7:29     ` Namhyung Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2025-03-13  7:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

On Mon, Mar 10, 2025 at 02:55:52PM -0700, Namhyung Kim wrote:
> On Mon, Mar 10, 2025 at 04:45:33PM -0300, Arnaldo Carvalho de Melo wrote:
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > 
> > Do a simple bounds check to avoid this on new gcc versions:
> > 
> >   31    15.81 fedora:rawhide                : FAIL gcc version 15.0.1 20250225 (Red Hat 15.0.1-0) (GCC)
> >     In function 'callchain__fprintf_left_margin',
> >         inlined from 'callchain__fprintf_graph.constprop' at ui/stdio/hist.c:246:12:
> >     ui/stdio/hist.c:27:39: error: iteration 2147483647 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
> 
> Hmm.. does it warn about a signed integer overflow?
> 
> 2147483647 is 0x7fffffff in hex and it should be INT_MAX.
> I'm not sure what is the problem.

Maybe the aggressive loop optimization can unroll the loop more than the
INT_MAX...?  Anyway the fix is simple and makes sense.

> 
> 
> >        27 |         for (i = 0; i < left_margin; i++)
> >           |                                      ~^~
> >     ui/stdio/hist.c:27:23: note: within this loop
> >        27 |         for (i = 0; i < left_margin; i++)
> >           |                     ~~^~~~~~~~~~~~~
> >     cc1: all warnings being treated as errors
> >     --
> >     util/units.c: In function 'unit_number__scnprintf':
> >     util/units.c:67:24: error: initializer-string for array of 'char' is too long [-Werror=unterminated-string-initialization]
> >        67 |         char unit[4] = "BKMG";
> >           |                        ^~~~~~
> >     cc1: all warnings being treated as errors
> 
> This part belongs to the previous commit. :)

I'll drop this part.

Thanks,
Namhyung

> 
> > 
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > Cc: Ian Rogers <irogers@google.com>
> > Cc: James Clark <james.clark@linaro.org>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Kan Liang <kan.liang@linux.intel.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> >  tools/perf/ui/stdio/hist.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
> > index 74b2c619c56c8ba3..7ac4b98e28bca82e 100644
> > --- a/tools/perf/ui/stdio/hist.c
> > +++ b/tools/perf/ui/stdio/hist.c
> > @@ -1,4 +1,5 @@
> >  // SPDX-License-Identifier: GPL-2.0
> > +#include <limits.h>
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >  #include <linux/string.h>
> > @@ -24,6 +25,9 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
> >  	int i;
> >  	int ret = fprintf(fp, "            ");
> >  
> > +	if (left_margin > USHRT_MAX)
> > +		left_margin = USHRT_MAX;
> > +
> >  	for (i = 0; i < left_margin; i++)
> >  		ret += fprintf(fp, " ");
> >  
> > -- 
> > 2.48.1
> > 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] Some build fixes
  2025-03-10 19:45 [PATCH 0/3] Some build fixes Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2025-03-10 19:45 ` [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions Arnaldo Carvalho de Melo
@ 2025-03-13 16:29 ` Namhyung Kim
  3 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2025-03-13 16:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo

On Mon, 10 Mar 2025 16:45:30 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Hi Namhyung,
> 
> 	Some fixes I noticed while building with my set of containers.
> 
> Best regards,
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-03-13 16:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 19:45 [PATCH 0/3] Some build fixes Arnaldo Carvalho de Melo
2025-03-10 19:45 ` [PATCH 1/3] libapi: Add missing header with NAME_MAX define to io_dir.h Arnaldo Carvalho de Melo
2025-03-10 19:45 ` [PATCH 2/3] perf units: Fix insufficient array space Arnaldo Carvalho de Melo
2025-03-10 19:45 ` [PATCH 3/3] perf hist stdio: Do bounds check when printing callchains to avoid UB with new gcc versions Arnaldo Carvalho de Melo
2025-03-10 21:55   ` Namhyung Kim
2025-03-13  7:29     ` Namhyung Kim
2025-03-13 16:29 ` [PATCH 0/3] Some build fixes Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).