Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Perale via buildroot <buildroot@buildroot.org>
To: Florian Larysch <fl@n621.de>
Cc: Thomas Perale <thomas.perale@mind.be>, buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 2025.02.x 1/1] package/pahole: fix build on modern toolchains
Date: Fri, 24 Jul 2026 16:14:09 +0200	[thread overview]
Message-ID: <20260724141410.477344-1-thomas.perale@mind.be> (raw)
In-Reply-To: <20260714153242.20947-1-fl@n621.de>

In reply of:
> When building pahole using a modern GCC (e.g. when building
> host-pahole), discarded-qualifiers warnings are produced. In builds that
> don't set CMAKE_BUILD_TYPE=Release, -Werror gets set and causes a build
> failure.
> 
> Fix this by backporting the applicable parts of an upstream patch and
> fixing a remaining issue that implicitly got refactored away upstream
> already.
> 
> Signed-off-by: Florian Larysch <fl@n621.de>

Applied to 2025.02.x. Thanks

> ---
>  ...scarded-qualifiers-for-strchr-strstr.patch | 134 ++++++++++++++++++
>  ...reserve-const-ness-of-bsearch-result.patch |  38 +++++
>  2 files changed, 172 insertions(+)
>  create mode 100644 package/pahole/0002-pahole-Fix-discarded-qualifiers-for-strchr-strstr.patch
>  create mode 100644 package/pahole/0003-pahole-preserve-const-ness-of-bsearch-result.patch
> 
> diff --git a/package/pahole/0002-pahole-Fix-discarded-qualifiers-for-strchr-strstr.patch b/package/pahole/0002-pahole-Fix-discarded-qualifiers-for-strchr-strstr.patch
> new file mode 100644
> index 0000000000..fc0bcc4f7c
> --- /dev/null
> +++ b/package/pahole/0002-pahole-Fix-discarded-qualifiers-for-strchr-strstr.patch
> @@ -0,0 +1,134 @@
> +From 5eeb534e02183bcaf2b86f71e0e96efa2d2ce3d0 Mon Sep 17 00:00:00 2001
> +From: Damien Hourtoulle <damien.hourtoulle@gmail.com>
> +Date: Wed, 11 Mar 2026 15:09:39 +0100
> +Subject: [PATCH] pahole: Fix discarded-qualifiers for strchr/strstr.
> +
> +Glibc 2.43 added C23 const-preserving overloads :
> +https://sourceware.org/glibc/wiki/Release/2.43.
> +
> +For the function prototype__new, fix local variable declaration to use
> +the correct const char* type instead of char*, removing the need to
> +discard the const qualifier.
> +
> +Also fix a pre-existing bug in type__find_type_enum: when iterating
> +over a '+'-concatenated list of enum names, after advancing to the next
> +segment the new separator was not nullified, causing "second+third" to
> +be passed to cu__find_enumeration_by_name instead of "second".  Add a
> +null check before writing to sep_mutable to avoid a null dereference
> +when no further '+' is present.
> +
> +Signed-off-by: Damien Hourtoulle <damien.hourtoulle@gmail.com>
> +Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> +Link: https://lore.kernel.org/dwarves/20260311140938.81459-2-d.hourtoulle@geoide.fr/
> +
> +Upstream: https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=ba31cfa08ffcfe6ff5757f325de5b03ca157cb78
> +[Florian: Backport of the applicable bits to v1.27]
> +Signed-off-by: Florian Larysch <fl@n621.de>
> +---
> + pahole.c | 35 ++++++++++++++++++-----------------
> + 1 file changed, 18 insertions(+), 17 deletions(-)
> +
> +diff --git a/pahole.c b/pahole.c
> +index 954498d..3dcb525 100644
> +--- a/pahole.c
> ++++ b/pahole.c
> +@@ -2505,7 +2505,7 @@ static int64_t type_instance__int_value(struct type_instance *instance, const ch
> + 	int byte_offset = 0;
> + 
> + 	if (!member) {
> +-		char *sep = strchr(member_name_orig, '.');
> ++		const char *sep = strchr(member_name_orig, '.');
> + 
> + 		if (!sep)
> + 			return -1;
> +@@ -2518,8 +2518,8 @@ static int64_t type_instance__int_value(struct type_instance *instance, const ch
> + 		char *member_name = member_name_alloc;
> + 		struct type *type = instance->type;
> + 
> +-		sep = member_name_alloc + (sep - member_name_orig);
> +-		*sep = 0;
> ++		char *sep_mutable = member_name_alloc + (sep - member_name_orig);  // sep mutable for the copy
> ++		*sep_mutable = 0;
> + 
> + 		while (1) {
> + 			member = type__find_member_by_name(type, member_name);
> +@@ -2532,9 +2532,9 @@ out_free_member_name:
> + 			type = tag__type(cu__type(cu, member->tag.type));
> + 			if (type == NULL)
> + 				goto out_free_member_name;
> +-			member_name = sep + 1;
> +-			sep = strchr(member_name, '.');
> +-			if (!sep)
> ++			member_name = sep_mutable + 1;
> ++			sep_mutable = strchr(member_name, '.');
> ++			if (!sep_mutable)
> + 				break;
> + 
> + 		}
> +@@ -2972,7 +2972,7 @@ static struct prototype *prototype__new(const char *expression)
> + 
> + 	strcpy(prototype->name, expression);
> + 
> +-	const char *name = prototype->name;
> ++	char *name = prototype->name;
> + 
> + 	prototype->nr_args = 0;
> + 
> +@@ -2986,10 +2986,9 @@ static struct prototype *prototype__new(const char *expression)
> + 	if (args_close == NULL)
> + 		goto out_no_closing_parens;
> + 
> ++	*args_open++ = *args_close = '\0';
> + 	char *args = args_open;
> + 
> +-	*args++ = *args_close = '\0';
> +-
> + 	while (isspace(*args))
> + 		++args;
> + 
> +@@ -3136,7 +3135,7 @@ static int type__find_type_enum(struct type *type, struct cu *cu, const char *ty
> + 		return type__add_type_enum(type, te, cu);
> + 
> + 	// Now look at a 'virtual enum', i.e. the concatenation of multiple enums
> +-	char *sep = strchr(type_enum, '+');
> ++	const char *sep = strchr(type_enum, '+');
> + 
> + 	if (!sep)
> + 		return -1;
> +@@ -3148,13 +3147,13 @@ static int type__find_type_enum(struct type *type, struct cu *cu, const char *ty
> + 
> + 	int ret = -1;
> + 
> +-	sep = type_enums + (sep - type_enum);
> ++	char *sep_mutable = type_enums + (sep - type_enum);
> ++	char *cur = type_enums;
> + 
> +-	type_enum = type_enums;
> +-	*sep = '\0';
> ++	*sep_mutable = '\0';
> + 
> + 	while (1) {
> +-		te = cu__find_enumeration_by_name(cu, type_enum, NULL);
> ++		te = cu__find_enumeration_by_name(cu, cur, NULL);
> + 
> + 		if (!te)
> + 			goto out;
> +@@ -3163,10 +3162,12 @@ static int type__find_type_enum(struct type *type, struct cu *cu, const char *ty
> + 		if (ret)
> + 			goto out;
> + 
> +-		if (sep == NULL)
> ++		if (sep_mutable == NULL)
> + 			break;
> +-		type_enum = sep + 1;
> +-		sep = strchr(type_enum, '+');
> ++		cur = sep_mutable + 1;
> ++		sep_mutable = strchr(cur, '+');
> ++		if (sep_mutable)
> ++			*sep_mutable = '\0';
> + 	}
> + 
> + 	ret = 0;
> +-- 
> +2.55.0
> +
> diff --git a/package/pahole/0003-pahole-preserve-const-ness-of-bsearch-result.patch b/package/pahole/0003-pahole-preserve-const-ness-of-bsearch-result.patch
> new file mode 100644
> index 0000000000..7a4cddf5d1
> --- /dev/null
> +++ b/package/pahole/0003-pahole-preserve-const-ness-of-bsearch-result.patch
> @@ -0,0 +1,38 @@
> +From f510bf5d3f3e3405710311ceb4a3539267218bde Mon Sep 17 00:00:00 2001
> +From: Florian Larysch <larysch@fixme.gmbh>
> +Date: Tue, 14 Jul 2026 16:03:12 +0200
> +Subject: [PATCH] pahole: preserve const-ness of bsearch result
> +MIME-Version: 1.0
> +Content-Type: text/plain; charset=UTF-8
> +Content-Transfer-Encoding: 8bit
> +
> +Fixes:
> +
> +pahole/btf_encoder.c: In function ‘btf_encoder__tag_kfunc’:
> +pahole/btf_encoder.c:1526:16: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
> + 1526 |         target = bsearch(&key, base, cnt, sizeof(key), btf_func_cmp);
> +      |                ^
> +
> +Upstream: N/A (implicitly fixed as part of a refactor in commit c567717
> +("btf_encoder: Refactor btf_encoder__tag_kfuncs()"), released in v1.30)
> +Signed-off-by: Florian Larysch <fl@n621.de>
> +---
> + btf_encoder.c | 2 +-
> + 1 file changed, 1 insertion(+), 1 deletion(-)
> +
> +diff --git a/btf_encoder.c b/btf_encoder.c
> +index c2df2bc..4118028 100644
> +--- a/btf_encoder.c
> ++++ b/btf_encoder.c
> +@@ -1516,7 +1516,7 @@ static int btf_encoder__tag_kfunc(struct btf_encoder *encoder, struct gobuffer *
> + {
> + 	struct btf_func key = { .name = kfunc };
> + 	struct btf *btf = encoder->btf;
> +-	struct btf_func *target;
> ++	const struct btf_func *target;
> + 	const void *base;
> + 	unsigned int cnt;
> + 	int err = -1;
> +-- 
> +2.55.0
> +
> -- 
> 2.55.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

      reply	other threads:[~2026-07-24 14:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 15:32 [Buildroot] [PATCH 2025.02.x 1/1] package/pahole: fix build on modern toolchains Florian Larysch
2026-07-24 14:14 ` Thomas Perale via buildroot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724141410.477344-1-thomas.perale@mind.be \
    --to=buildroot@buildroot.org \
    --cc=fl@n621.de \
    --cc=thomas.perale@mind.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox