Skip to contentSkip to conversation

Backport fixes for -Wdiscarded-qualifiers and -Wnonnull with newer glibc

PATCH Superseded Shreenidhi Shedi 2 participants 20 messages May 9 – May 10

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Backport fixes for -Wdiscarded-qualifiers and -Wnonnull with newer glibc

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Hi all,

This patch series backports a number of patches from master to 6.1.y to fix -Wdiscarded-qualifiers and -Wnonnull build issues with newer glibc versions.

Arnaldo Carvalho de Melo (12):
perf diff: Constify strchr() return variables
perf test bpf: Address error about non-null argument for epoll_pwait
2nd arg
perf trace: Deal with compiler const checks
perf tools: Use const for variables receiving str{str,r?chr}() returns perf strlist: Don't write to const memory
perf metricgroup: Constify variables storing the result of strchr() on
const tables
perf session: Don't write to memory pointed to a const pointer perf trace-event: Constify variables storing the result of strchr() on
const tables
perf units: Constify variables storing the result of strchr() on const
tables
perf time-utils: Constify variables storing the result of strchr() on
const tables
perf demangle-java: Constify variables storing the result of strchr()
on const tables
perf bpf-event: Constify variables storing the result of strchr() on
const tables

Dr. David Alan Gilbert (1):
perf tools: Remove unused color_fwrite_lines

Mikhail Gavrilov (1):
libbpf: Fix -Wdiscarded-qualifiers under C23

Shreenidhi Shedi (4):
perf list: Fix -Wdiscarded-qualifiers under C23 perf parse-events: Fix -Wdiscarded-qualifiers under C23 perf bpf: Fix -Wdiscarded-qualifiers under C23 perf parse-events:: Fix -Wdiscarded-qualifiers under C23

 tools/lib/bpf/libbpf.c             |  2 +-
 tools/perf/builtin-diff.c          | 12 +++++-------
 tools/perf/builtin-list.c          |  3 ++-
 tools/perf/builtin-trace.c         |  2 +-
 tools/perf/jvmti/libjvmti.c        |  2 +-
 tools/perf/tests/bpf.c             |  3 ++-
 tools/perf/util/bpf-event.c        |  3 ++-
 tools/perf/util/bpf-loader.c       |  2 +-
 tools/perf/util/color.c            | 28 ----------------------------
 tools/perf/util/color.h            |  1 -
 tools/perf/util/demangle-java.c    |  2 +-
 tools/perf/util/evlist.c           |  3 ++-
 tools/perf/util/metricgroup.c      |  3 +--
 tools/perf/util/parse-events.c     |  2 +-
 tools/perf/util/print-events.c     |  4 ++--
 tools/perf/util/session.c          |  6 +++---
 tools/perf/util/strlist.c          | 12 ++++++++----
 tools/perf/util/time-utils.c       |  4 ++--
 tools/perf/util/trace-event-info.c |  2 +-
 tools/perf/util/units.c            |  2 +-
 20 files changed, 37 insertions(+), 61 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/18 libbpf: Fix -Wdiscarded-qualifiers under C23

From: Mikhail Gavrilov <[email protected]>

commit d70f79fef65810faf64dbae1f3a1b5623cdb2345 upstream

glibc ≥ 2.42 (GCC 15) defaults to -std=gnu23, which promotes -Wdiscarded-qualifiers to an error.

In C23, strstr() and strchr() return "const char *".

Change variable types to const char * where the pointers are never modified (res, sym_sfx, next_path).

---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 7bd6aff6e260..33b214a91338 100644
@@ -10748,7 +10748,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
 		if (!search_paths[i])
 			continue;
 		for (s = search_paths[i]; s != NULL; s = strchr(s, ':')) {
-			char *next_path;
+			const char *next_path;
 			int seg_len;
 
 			if (s[0] == ':')
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/18 perf diff: Constify strchr() return variables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit f6f41aef53761517391b6192fe5b4bc30b2d717a upstream

Newer glibc versions return const char for strchr() when the 's' arg is const, change the return variable to const to match that.

Also we don't need to turn that ',' into a '\0', as strtol() will stop in the first invalid char. No need to touch read only memory.

First noticed with fedora 44.

---
 tools/perf/builtin-diff.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
tools/perf/builtin-diff.c +5 -7
index ed07cc6cca56..9a05d67f541b 100644
@@ -177,10 +177,9 @@ static struct header_column {
 	}
 };
 
-static int setup_compute_opt_wdiff(char *opt)
+static int setup_compute_opt_wdiff(const char *opt)
 {
-	char *w1_str = opt;
-	char *w2_str;
+	const char *w1_str = opt, *w2_str;
 
 	int ret = -EINVAL;
 
@@ -191,8 +190,7 @@ static int setup_compute_opt_wdiff(char *opt)
 	if (!w2_str)
 		goto out;
 
-	*w2_str++ = 0x0;
-	if (!*w2_str)
+	if (!*++w2_str)
 		goto out;
 
 	compute_wdiff_w1 = strtol(w1_str, NULL, 10);
@@ -213,7 +211,7 @@ static int setup_compute_opt_wdiff(char *opt)
 	return ret;
 }
 
-static int setup_compute_opt(char *opt)
+static int setup_compute_opt(const char *opt)
 {
 	if (compute == COMPUTE_WEIGHTED_DIFF)
 		return setup_compute_opt_wdiff(opt);
@@ -233,7 +231,7 @@ static int setup_compute(const struct option *opt, const char *str,
 	char *cstr = (char *) str;
 	char buf[50];
 	unsigned i;
-	char *option;
+	const char *option;
 
 	if (!str) {
 		*cp = COMPUTE_DELTA;
Signature · 1 line
2.54.0
#3 lore raw

PATCH 3/18 perf test bpf: Address error about non-null argument for epoll_pwait 2nd arg

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit ed847e30f001b207013b6136c264454d7560557f upstream

First noticed on Fedora Rawhide:

tests/bpf.c: In function ‘epoll_pwait_loop’:
tests/bpf.c:36:17: error: argument 2 null where non-null expected [-Werror=nonnull]

     36 |                 epoll_pwait(-(i + 1), NULL, 0, 0, NULL);
        |                 ^~~~~~~~~~~

In file included from tests/bpf.c:5:
/usr/include/sys/epoll.h:134:12: note: in a call to function ‘epoll_pwait’ declared ‘nonnull’
134 | extern int epoll_pwait (int __epfd, struct epoll_event *__events,
| ^~~~~~~~~~~

[perfbuilder@27cfe44d67ed perf-6.5.0-rc2]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-13.2.1-20230728/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.1 20230728 (Red Hat 13.2.1-1) (GCC)
[perfbuilder@27cfe44d67ed perf-6.5.0-rc2]$

Just add that argument to address this compiler warning.

---
 tools/perf/tests/bpf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/bpf.c +2 -1
index 6a4235a9cf57..d5bf0e47a48a 100644
@@ -29,11 +29,12 @@
 
 static int epoll_pwait_loop(void)
 {
+	struct epoll_event events;
 	int i;
 
 	/* Should fail NR_ITERS times */
 	for (i = 0; i < NR_ITERS; i++)
-		epoll_pwait(-(i + 1), NULL, 0, 0, NULL);
+		epoll_pwait(-(i + 1), &events, 0, 0, NULL);
 	return 0;
 }
 
Signature · 1 line
2.54.0
#4 lore raw

PATCH 4/18 perf list: Fix -Wdiscarded-qualifiers under C23

In reply to Shreenidhi Shedi

builtin-list.c:104:31: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
104 | else if ((sep = strchr(argv[i], ':')) != NULL) {

glibc >= 2.42 defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error.

---
 tools/perf/builtin-list.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-list.c +2 -1
index 58e1ec1654ef..a37f3b8a597c 100644
@@ -75,7 +75,8 @@ int cmd_list(int argc, const char **argv)
 	}
 
 	for (i = 0; i < argc; ++i) {
-		char *sep, *s;
+		const char *sep;
+		char *s;
 
 		if (strcmp(argv[i], "tracepoint") == 0)
 			print_tracepoint_events(NULL, NULL, raw_dump);
Signature · 1 line
2.54.0
#5 lore raw

PATCH 5/18 perf trace: Deal with compiler const checks

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 2c850606a46b319d5128bda59f67b1fc642d94ef upstream

The strchr() function these days return const/non-const based on the arg it receives, and sometimes we need to use casts when we're dealing with variables that are used in code that needs to safely change the returned value and sometimes not (as it points to really const areas).

Tweak one such case.

---
 tools/perf/builtin-trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-trace.c +1 -1
index 441655e659c2..313eb0929324 100644
@@ -4622,7 +4622,7 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
 	}
 
 	while (1) {
-		if ((sep = strchr(s, ',')) != NULL)
+		if ((sep = strchr((char *)s, ',')) != NULL)
 			*sep = '\0';
 
 		list = 0;
Signature · 1 line
2.54.0
#6 lore raw

PATCH 6/18 perf tools: Use const for variables receiving str{str,r?chr}() returns

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 45718bce7daf39c618188b70a52644bb5a2f968a upstream

Newer glibc versions return const char for str{str,chr}() where the haystack/s is const so to avoid warnings like these on fedora 44 change some variables to const:

36 8.17 fedora:44 : FAIL gcc version 15.2.1 20251111 (Red Hat 15.2.1-4) (GCC)
libbpf.c: In function 'kallsyms_cb':
libbpf.c:8489:13: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
8489 | res = strstr(sym_name, ".llvm.");

---
 tools/perf/jvmti/libjvmti.c | 2 +-
 tools/perf/util/evlist.c    | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/jvmti/libjvmti.c +1 -1
index fcca275e5bf9..d6b04d0fd35a 100644
@@ -142,7 +142,7 @@ copy_class_filename(const char * class_sign, const char * file_name, char * resu
 	*/
 	if (*class_sign == 'L') {
 		int j, i = 0;
-		char *p = strrchr(class_sign, '/');
+		const char *p = strrchr(class_sign, '/');
 		if (p) {
 			/* drop the 'L' prefix and copy up to the final '/' */
 			for (i = 0; i < (p - class_sign); i++)
tools/perf/util/evlist.c +2 -1
index 41bbe6f85b0d..391a694ae2af 100644
@@ -1885,7 +1885,8 @@ static int evlist__parse_control_fifo(const char *str, int *ctl_fd, int *ctl_fd_
 
 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close)
 {
-	char *comma = NULL, *endptr = NULL;
+	const char *comma = NULL;
+	char *endptr = NULL;
 
 	*ctl_fd_close = false;
 
Signature · 1 line
2.54.0
#7 lore raw

PATCH 7/18 perf parse-events: Fix -Wdiscarded-qualifiers under C23

In reply to Shreenidhi Shedi

glibc >= 2.42 defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error.

util/print-events.c:206:21: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
206 | buf = strchr(nd->s, '@');

util/print-events.c:215:29: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
215 | ptr = strchr(nd2->s, '@');

---
 tools/perf/util/print-events.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/print-events.c +2 -2
index c4d5d87fae2f..1ef1a3ed8051 100644
@@ -203,7 +203,7 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob,
 	strlist__delete(bidlist);
 
 	strlist__for_each_entry(nd, sdtlist) {
-		buf = strchr(nd->s, '@');
+		buf = strchr((char *)nd->s, '@');
 		if (buf)
 			*(buf++) = '\0';
 		if (name_only) {
@@ -212,7 +212,7 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob,
 		}
 		nd2 = strlist__next(nd);
 		if (nd2) {
-			ptr = strchr(nd2->s, '@');
+			ptr = strchr((char *)nd2->s, '@');
 			if (ptr)
 				*ptr = '\0';
 			if (strcmp(nd->s, nd2->s) == 0)
Signature · 1 line
2.54.0
#8 lore raw

PATCH 8/18 perf tools: Remove unused color_fwrite_lines

In reply to Shreenidhi Shedi

From: "Dr. David Alan Gilbert" <[email protected]>

commit c7c1bb78f3eec716bc35f58d74592331cc3281b2 upstream

color_fwrite_lines() was added by 2009's commit 8fc0321f1ad0 ("perf_counter tools: Add color terminal output support")

but has never been used.

Remove it.

---
 tools/perf/util/color.c | 28 ----------------------------
 tools/perf/util/color.h |  1 -
 2 files changed, 29 deletions(-)
tools/perf/util/color.c +0 -28
index bffbdd216a6a..e51f0a676a22 100644
@@ -93,34 +93,6 @@ int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
 	return r;
 }
 
-/*
- * This function splits the buffer by newlines and colors the lines individually.
- *
- * Returns 0 on success.
- */
-int color_fwrite_lines(FILE *fp, const char *color,
-		size_t count, const char *buf)
-{
-	if (!*color)
-		return fwrite(buf, count, 1, fp) != 1;
-
-	while (count) {
-		char *p = memchr(buf, '\n', count);
-
-		if (p != buf && (fputs(color, fp) < 0 ||
-				fwrite(buf, p ? (size_t)(p - buf) : count, 1, fp) != 1 ||
-				fputs(PERF_COLOR_RESET, fp) < 0))
-			return -1;
-		if (!p)
-			return 0;
-		if (fputc('\n', fp) < 0)
-			return -1;
-		count -= p + 1 - buf;
-		buf = p + 1;
-	}
-	return 0;
-}
-
 const char *get_percent_color(double percent)
 {
 	const char *color = PERF_COLOR_NORMAL;
tools/perf/util/color.h +0 -1
index 01f7bed21c9b..aecf56dae73f 100644
@@ -39,7 +39,6 @@ int color_vsnprintf(char *bf, size_t size, const char *color,
 int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args);
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
 int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...);
-int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
 int value_color_snprintf(char *bf, size_t size, const char *fmt, double value);
 int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...);
 int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...);
Signature · 1 line
2.54.0
#9 lore raw

PATCH 9/18 perf strlist: Don't write to const memory

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 678ed6b707e4b2db250f255d2f959322896dae65 upstream

Do a strdup to the list string and parse from it, free at the end.

This is to deal with newer glibcs const-correctness.

---
 tools/perf/util/strlist.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/perf/util/strlist.c +8 -4
index 8a868cbeffae..98883672fcf4 100644
@@ -139,21 +139,25 @@ static int strlist__parse_list_entry(struct strlist *slist, const char *s,
 	return err;
 }
 
-static int strlist__parse_list(struct strlist *slist, const char *s, const char *subst_dir)
+static int strlist__parse_list(struct strlist *slist, const char *list, const char *subst_dir)
 {
-	char *sep;
+	char *sep, *s = strdup(list), *sdup = s;
 	int err;
 
+	if (s == NULL)
+		return -ENOMEM;
+
 	while ((sep = strchr(s, ',')) != NULL) {
 		*sep = '\0';
 		err = strlist__parse_list_entry(slist, s, subst_dir);
-		*sep = ',';
 		if (err != 0)
 			return err;
 		s = sep + 1;
 	}
 
-	return *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
+	err = *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
+	free(sdup);
+	return err;
 }
 
 struct strlist *strlist__new(const char *list, const struct strlist_config *config)
Signature · 1 line
2.54.0
#10 lore raw

PATCH 10/18 perf metricgroup: Constify variables storing the result of strchr() on const tables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit b42868624c7d00206f77d19a6fbfea73a44ff6f2 upstream

As newer glibcs will propagate the const attribute of the searched table to its return.

---
 tools/perf/util/metricgroup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/metricgroup.c +1 -2
index 4c98ac29ee13..664045fa0c8e 100644
@@ -644,11 +644,10 @@ static const char *code_characters = ",-=@";
 
 static int encode_metric_id(struct strbuf *sb, const char *x)
 {
-	char *c;
 	int ret = 0;
 
 	for (; *x; x++) {
-		c = strchr(code_characters, *x);
+		const char *c = strchr(code_characters, *x);
 		if (c) {
 			ret = strbuf_addch(sb, '!');
 			if (ret)
Signature · 1 line
2.54.0
#11 lore raw

PATCH 11/18 perf session: Don't write to memory pointed to a const pointer

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit f1321cce848c558fde4c0c6bcd5e53f3cefd3af2 upstream

Since it is freshly allocated just attribute it to a non-const pointer and then change it via that pointer.

That way we avoid const-correctness warnings in recent glibc versions.

---
 tools/perf/util/session.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/session.c +3 -3
index 1c4d124b1053..9d11cf2aab0c 100644
@@ -2641,7 +2641,7 @@ bool perf_session__has_traces(struct perf_session *session, const char *msg)
 
 int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name, u64 addr)
 {
-	char *bracket;
+	char *bracket, *name;
 	struct ref_reloc_sym *ref;
 	struct kmap *kmap;
 
@@ -2649,13 +2649,13 @@ int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name, u6
 	if (ref == NULL)
 		return -ENOMEM;
 
-	ref->name = strdup(symbol_name);
+	ref->name = name = strdup(symbol_name);
 	if (ref->name == NULL) {
 		free(ref);
 		return -ENOMEM;
 	}
 
-	bracket = strchr(ref->name, ']');
+	bracket = strchr(name, ']');
 	if (bracket)
 		*bracket = '\0';
 
Signature · 1 line
2.54.0
#12 lore raw

PATCH 12/18 perf trace-event: Constify variables storing the result of strchr() on const tables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 97b81df7225830c4db3c17ed1235d2f3eb613d3d uptream

As newer glibcs will propagate the const attribute of the searched table to its return.

---
 tools/perf/util/trace-event-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/trace-event-info.c +1 -1
index 892c323b4ac9..5a6dec2dc0d8 100644
@@ -477,7 +477,7 @@ static struct tracepoint_path *tracepoint_id_to_path(u64 config)
 static struct tracepoint_path *tracepoint_name_to_path(const char *name)
 {
 	struct tracepoint_path *path = zalloc(sizeof(*path));
-	char *str = strchr(name, ':');
+	const char *str = strchr(name, ':');
 
 	if (path == NULL || str == NULL) {
 		free(path);
Signature · 1 line
2.54.0
#13 lore raw

PATCH 13/18 perf units: Constify variables storing the result of strchr() on const tables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 0e14cb3b24f8f301cf6490a4493afc98321ed5bb upstream

As newer glibcs will propagate the const attribute of the searched table to its return.

---
 tools/perf/util/units.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/units.c +1 -1
index 4c6a86e1cb54..0bbacf5a29aa 100644
@@ -12,7 +12,7 @@ unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
 	struct parse_tag *i = tags;
 
 	while (i->tag) {
-		char *s = strchr(str, i->tag);
+		const char *s = strchr(str, i->tag);
 
 		if (s) {
 			unsigned long int value;
Signature · 1 line
2.54.0
#14 lore raw

PATCH 14/18 perf bpf: Fix -Wdiscarded-qualifiers under C23

In reply to Shreenidhi Shedi

glibc >= 2.42 defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error.

util/bpf-loader.c: In function 'config_bpf_program':
util/bpf-loader.c:588:27: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 588 | char *s = strchr(main_str, ':');

---
 tools/perf/util/bpf-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/bpf-loader.c +1 -1
index f4adeccdbbcb..7f4e774a3435 100644
@@ -585,7 +585,7 @@ config_bpf_program(struct bpf_program *prog)
 		goto errout;
 
 	if (is_tp) {
-		char *s = strchr(main_str, ':');
+		const char *s = strchr(main_str, ':');
 
 		priv->is_tp = true;
 		priv->sys_name = strndup(main_str, s - main_str);
Signature · 1 line
2.54.0
#15 lore raw

PATCH 15/18 perf time-utils: Constify variables storing the result of strchr() on const tables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 21c0bc9144834e39762dd6fddbb255ebb80cf079 upstream

As newer glibcs will propagate the const attribute of the searched table to its return.

---
 tools/perf/util/time-utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/time-utils.c +2 -2
index 1b91ccd4d523..d43c4577d7eb 100644
@@ -325,7 +325,7 @@ static int percent_comma_split(struct perf_time_interval *ptime_buf, int num,
 }
 
 static int one_percent_convert(struct perf_time_interval *ptime_buf,
-			       const char *ostr, u64 start, u64 end, char *c)
+			       const char *ostr, u64 start, u64 end, const char *c)
 {
 	char *str;
 	int len = strlen(ostr), ret;
@@ -358,7 +358,7 @@ static int one_percent_convert(struct perf_time_interval *ptime_buf,
 int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
 				 const char *ostr, u64 start, u64 end)
 {
-	char *c;
+	const char *c;
 
 	/*
 	 * ostr example:
Signature · 1 line
2.54.0
#16 lore raw

PATCH 16/18 perf demangle-java: Constify variables storing the result of strchr() on const tables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 79bba3a1834e7ba6c437674582cc9f3ae6fb638c upstream

As newer glibcs will propagate the const attribute of the searched table to its return.

---
 tools/perf/util/demangle-java.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/demangle-java.c +1 -1
index ddf33d58bcd3..c3cb327ed562 100644
@@ -158,7 +158,7 @@ char *
 java_demangle_sym(const char *str, int flags)
 {
 	char *buf, *ptr;
-	char *p;
+	const char *p;
 	size_t len, l1 = 0;
 
 	if (!str)
Signature · 1 line
2.54.0
#17 lore raw

PATCH 17/18 perf parse-events:: Fix -Wdiscarded-qualifiers under C23

In reply to Shreenidhi Shedi

glibc >= 2.42 defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error.

---
 tools/perf/util/parse-events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/parse-events.c +1 -1
index 5973f46c2375..e3b7950331bc 100644
@@ -1647,7 +1647,7 @@ int parse_events__modifier_group(struct list_head *list,
  */
 static bool is_same_uncore_block(const char *pmu_name_a, const char *pmu_name_b)
 {
-	char *end_a, *end_b;
+	const char *end_a, *end_b;
 
 	end_a = strrchr(pmu_name_a, '_');
 	end_b = strrchr(pmu_name_b, '_');
Signature · 1 line
2.54.0
#18 lore raw

PATCH 18/18 perf bpf-event: Constify variables storing the result of strchr() on const tables

In reply to Shreenidhi Shedi

From: Arnaldo Carvalho de Melo <[email protected]>

commit 8bf093acb3f1f07d846c86e32308f9f9954ed579 upstream

As newer glibcs will propagate the const attribute of the searched table to its return.

---
 tools/perf/util/bpf-event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/bpf-event.c +2 -1
index 91c7bfa82a50..fbaab3d3a476 100644
@@ -411,7 +411,8 @@ kallsyms_process_symbol(void *data, const char *_name,
 			char type __maybe_unused, u64 start)
 {
 	char disp[KSYM_NAME_LEN];
-	char *module, *name;
+	const char *module;
+	char *name;
 	unsigned long id;
 	int err = 0;
 
Signature · 1 line
2.54.0
#19 lore raw
In reply to Shreenidhi Shedi
Quoted 56 lines · Shreenidhi Shedi

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Hi all,

This patch series backports a number of patches from master to 6.1.y to fix -Wdiscarded-qualifiers and -Wnonnull build issues with newer glibc versions.

Arnaldo Carvalho de Melo (12):
perf diff: Constify strchr() return variables
perf test bpf: Address error about non-null argument for epoll_pwait
2nd arg
perf trace: Deal with compiler const checks
perf tools: Use const for variables receiving str{str,r?chr}() returns perf strlist: Don't write to const memory
perf metricgroup: Constify variables storing the result of strchr() on
const tables
perf session: Don't write to memory pointed to a const pointer perf trace-event: Constify variables storing the result of strchr() on
const tables
perf units: Constify variables storing the result of strchr() on const
tables
perf time-utils: Constify variables storing the result of strchr() on
const tables
perf demangle-java: Constify variables storing the result of strchr()
on const tables
perf bpf-event: Constify variables storing the result of strchr() on
const tables

Dr. David Alan Gilbert (1):
perf tools: Remove unused color_fwrite_lines

Mikhail Gavrilov (1):
libbpf: Fix -Wdiscarded-qualifiers under C23

Shreenidhi Shedi (4):
perf list: Fix -Wdiscarded-qualifiers under C23 perf parse-events: Fix -Wdiscarded-qualifiers under C23 perf bpf: Fix -Wdiscarded-qualifiers under C23 perf parse-events:: Fix -Wdiscarded-qualifiers under C23

 tools/lib/bpf/libbpf.c             |  2 +-
 tools/perf/builtin-diff.c          | 12 +++++-------
 tools/perf/builtin-list.c          |  3 ++-
 tools/perf/builtin-trace.c         |  2 +-
 tools/perf/jvmti/libjvmti.c        |  2 +-
 tools/perf/tests/bpf.c             |  3 ++-
 tools/perf/util/bpf-event.c        |  3 ++-
 tools/perf/util/bpf-loader.c       |  2 +-
 tools/perf/util/color.c            | 28 ----------------------------
 tools/perf/util/color.h            |  1 -
 tools/perf/util/demangle-java.c    |  2 +-
 tools/perf/util/evlist.c           |  3 ++-
 tools/perf/util/metricgroup.c      |  3 +--
Quoted 12 lines
 tools/perf/util/parse-events.c     |  2 +-
 tools/perf/util/print-events.c     |  4 ++--
 tools/perf/util/session.c          |  6 +++---
 tools/perf/util/strlist.c          | 12 ++++++++----
 tools/perf/util/time-utils.c       |  4 ++--
 tools/perf/util/trace-event-info.c |  2 +-
 tools/perf/util/units.c            |  2 +-
 20 files changed, 37 insertions(+), 61 deletions(-)
Signature · 1 line
2.54.0

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>