Skip to contentSkip to conversation

bpftool-native: Fix -Wdiscarded-qualifiers errors for glibc 2.42+

PATCH Superseded He Zhe 2 participants 3 messages May 9 – May 13

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

He Zhe

author
#0 lore raw

PATCH 1/1 bpftool-native: Fix -Wdiscarded-qualifiers errors for glibc 2.42+

Backport a patch from kernel to fix the following build errors.

bbpf.c: In function ‘kallsyms_cb’:

| libbpf.c:8192:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
|  8192 |         res = strstr(sym_name, ".llvm.");
|       |             ^
| libbpf.c: In function ‘avail_kallsyms_cb’:
| libbpf.c:11497:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
| 11497 |                 if (!(sym_sfx = strstr(sym_name, ".llvm.")))
|       |                               ^
| libbpf.c: In function ‘resolve_full_path’:
| libbpf.c:12085:35: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
| 12085 |                         next_path = strchr(s, ':');
|       |
---
 .../bpftool/bpftool-native_6.16.bb            |  5 +-
 ...-Fix-Wdiscarded-qualifiers-under-C23.patch | 69 +++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch
meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +4 -1
index fe3ad6138e..edc635517a 100644
@@ -9,7 +9,10 @@ DEPENDS = "binutils-native elfutils-native"
 
 inherit native bash-completion
 
-SRC_URI = "${KERNELORG_MIRROR}/linux/kernel/v6.x/linux-${PV}.tar.xz"
+SRC_URI = "\
+    ${KERNELORG_MIRROR}/linux/kernel/v6.x/linux-${PV}.tar.xz \
+    file://0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch \
+"
 SRC_URI[sha256sum] = "1a4be2fe6b5246aa4ac8987a8a4af34c42a8dd7d08b46ab48516bcc1befbcd83"
 
 S = "${UNPACKDIR}/linux-${PV}"
meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw
Quoted 84 lines · He Zhe via lists.openembedded.org

Backport a patch from kernel to fix the following build errors.

bbpf.c: In function ‘kallsyms_cb’:
| libbpf.c:8192:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]

|  8192 |         res = strstr(sym_name, ".llvm.");
|       |             ^
| libbpf.c: In function ‘avail_kallsyms_cb’:
| libbpf.c:11497:31: error: assignment discards ‘const’ qualifier from
pointer target type [-Werror=discarded-qualifiers]
| 11497 |                 if (!(sym_sfx = strstr(sym_name, ".llvm.")))
|       |                               ^
| libbpf.c: In function ‘resolve_full_path’:
| libbpf.c:12085:35: error: assignment discards ‘const’ qualifier from
pointer target type [-Werror=discarded-qualifiers]
| 12085 |                         next_path = strchr(s, ':');
|       |
---
 .../bpftool/bpftool-native_6.16.bb            |  5 +-
 ...-Fix-Wdiscarded-qualifiers-under-C23.patch | 69 +++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644

meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +4 -1
index fe3ad6138e..edc635517a 100644
@@ -9,7 +9,10 @@ DEPENDS = "binutils-native elfutils-native"
 
 inherit native bash-completion
 
-SRC_URI = "${KERNELORG_MIRROR}/linux/kernel/v6.x/linux-${PV}.tar.xz"
+SRC_URI = "\
+    ${KERNELORG_MIRROR}/linux/kernel/v6.x/linux-${PV}.tar.xz \
+    file://0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch \
+"
 SRC_URI[sha256sum] =

"1a4be2fe6b5246aa4ac8987a8a4af34c42a8dd7d08b46ab48516bcc1befbcd83"

S = "${UNPACKDIR}/linux-${PV}"
diff --git a/meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch b/meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch new file mode 100644
index 0000000000..76b9aabb54
--- /dev/null
+++
b/meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +22 -0
@@ -0,0 +1,69 @@
+From ab21cf885fb2af179c44d8beeabd716133b9385d Mon Sep 17 00:00:00 2001
+From: Mikhail Gavrilov <[email protected]>
+Date: Sat, 6 Dec 2025 14:28:25 +0500
+Subject: [PATCH] libbpf: Fix -Wdiscarded-qualifiers under C23
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+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).
+
+Suggested-by: Florian Weimer <[email protected]>
+Suggested-by: Andrii Nakryiko <[email protected]>
+Signed-off-by: Mikhail Gavrilov <[email protected]>
+Link:

https://lore.kernel.org/r/[email protected]
+Signed-off-by: Alexei Starovoitov <[email protected]>
+[ shung-hsi.yu: needed to fix kernel build failure due to libbpf since glibc

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +5 -0
+  2.43+ (which adds 'const' qualifier to strstr) ]
+Signed-off-by: Shung-Hsi Yu <[email protected]>
+Signed-off-by: Greg Kroah-Hartman <[email protected]>
+
+Upstream-Status: Backport[
Quoted 3 lines

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.18.y&id=ab21cf885fb2af179c44d8beeabd716133b9385d
]

This seems to be malformed ( add a space after 'Backport' )

Quoted 59 lines
meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +10 -0
+Signed-off-by: He Zhe <[email protected]>
+---
+ tools/lib/bpf/libbpf.c | 7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
+index dd3b2f57082d..9c98c6adb6d0 100644
+--- a/tools/lib/bpf/libbpf.c
++++ b/tools/lib/bpf/libbpf.c
+@@ -8245,7 +8245,7 @@ static int kallsyms_cb(unsigned long long sym_addr,

char sym_type,

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +9 -0
+       struct bpf_object *obj = ctx;
+       const struct btf_type *t;
+       struct extern_desc *ext;
+-      char *res;
++      const char *res;
+
+       res = strstr(sym_name, ".llvm.");
+       if (sym_type == 'd' && res)
+@@ -11574,7 +11574,8 @@ static int avail_kallsyms_cb(unsigned long long

sym_addr, char sym_type,

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +2 -0
+                *
+                *   [0] fb6a421fb615 ("kallsyms: Match symbols exactly

with CONFIG_LTO_CLANG")

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +8 -0
+                */
+-              char sym_trim[256], *psym_trim = sym_trim, *sym_sfx;
++              char sym_trim[256], *psym_trim = sym_trim;
++              const char *sym_sfx;
+
+               if (!(sym_sfx = strstr(sym_name, ".llvm.")))
+                       return 0;
+@@ -12159,7 +12160,7 @@ static int resolve_full_path(const char *file,

char *result, size_t result_sz)

meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb +11 -1
+               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] == ':')
+--
+2.34.1
+
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#126828):
https://lists.openembedded.org/g/openembedded-devel/message/126828
Mute This Topic: https://lists.openembedded.org/mt/119225487/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

author
#2 lore raw
Quoted 79 lines · Khem Raj

On Fri, May 8, 2026 at 8:08 PM He Zhe via lists.openembedded.org <https://urldefense.com/v3/__http://lists.openembedded.org__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesPAVTLMn$> <[email protected]> wrote:

    Backport a patch from kernel to fix the following build errors.

    bbpf.c: In function ‘kallsyms_cb’:
    | libbpf.c:8192:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    |  8192 |         res = strstr(sym_name, ".llvm.");
    |       |             ^
    | libbpf.c: In function ‘avail_kallsyms_cb’:
    | libbpf.c:11497:31: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    | 11497 |                 if (!(sym_sfx = strstr(sym_name, ".llvm.")))
    |       |                               ^
    | libbpf.c: In function ‘resolve_full_path’:
    | libbpf.c:12085:35: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    | 12085 |                         next_path = strchr(s, ':');
    |       |

    Signed-off-by: He Zhe <[email protected]>
    ---
     .../bpftool/bpftool-native_6.16.bb <https://urldefense.com/v3/__http://bpftool-native_6.16.bb__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesB2Q-Gdp$>            |  5 +-
     ...-Fix-Wdiscarded-qualifiers-under-C23.patch | 69 +++++++++++++++++++
     2 files changed, 73 insertions(+), 1 deletion(-)
     create mode 100644 meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch

    diff --git a/meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb <https://urldefense.com/v3/__http://bpftool-native_6.16.bb__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesB2Q-Gdp$> b/meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb <https://urldefense.com/v3/__http://bpftool-native_6.16.bb__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesB2Q-Gdp$>
    index fe3ad6138e..edc635517a 100644
    --- a/meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb <https://urldefense.com/v3/__http://bpftool-native_6.16.bb__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesB2Q-Gdp$>
    +++ b/meta-oe/recipes-kernel/bpftool/bpftool-native_6.16.bb <https://urldefense.com/v3/__http://bpftool-native_6.16.bb__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesB2Q-Gdp$>
    @@ -9,7 +9,10 @@ DEPENDS = "binutils-native elfutils-native"

     inherit native bash-completion

    -SRC_URI = "${KERNELORG_MIRROR}/linux/kernel/v6.x/linux-${PV}.tar.xz"
    +SRC_URI = "\
    +    ${KERNELORG_MIRROR}/linux/kernel/v6.x/linux-${PV}.tar.xz \
    +    file://0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch \
    +"
     SRC_URI[sha256sum] = "1a4be2fe6b5246aa4ac8987a8a4af34c42a8dd7d08b46ab48516bcc1befbcd83"

     S = "${UNPACKDIR}/linux-${PV}"
    diff --git a/meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch b/meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch
    new file mode 100644
    index 0000000000..76b9aabb54
    --- /dev/null
    +++ b/meta-oe/recipes-kernel/bpftool/bpftool/0001-libbpf-Fix-Wdiscarded-qualifiers-under-C23.patch
    @@ -0,0 +1,69 @@
    +From ab21cf885fb2af179c44d8beeabd716133b9385d Mon Sep 17 00:00:00 2001
    +From: Mikhail Gavrilov <[email protected]>
    +Date: Sat, 6 Dec 2025 14:28:25 +0500
    +Subject: [PATCH] libbpf: Fix -Wdiscarded-qualifiers under C23
    +MIME-Version: 1.0
    +Content-Type: text/plain; charset=UTF-8
    +Content-Transfer-Encoding: 8bit
    +
    +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).
    +
    +Suggested-by: Florian Weimer <[email protected]>
    +Suggested-by: Andrii Nakryiko <[email protected]>
    +Signed-off-by: Mikhail Gavrilov <[email protected]>
    +Link: https://lore.kernel.org/r/[email protected] <https://urldefense.com/v3/__https://lore.kernel.org/r/[email protected]__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesJitfz3F$>
    +Signed-off-by: Alexei Starovoitov <[email protected]>
    +[ shung-hsi.yu: needed to fix kernel build failure due to libbpf since glibc
    +  2.43+ (which adds 'const' qualifier to strstr) ]
    +Signed-off-by: Shung-Hsi Yu <[email protected]>
    +Signed-off-by: Greg Kroah-Hartman <[email protected]>
    +
    +Upstream-Status: Backport[https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.18.y&id=ab21cf885fb2af179c44d8beeabd716133b9385d <https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.18.y&id=ab21cf885fb2af179c44d8beeabd716133b9385d__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesMcSqBdC$>]
Quoted 1 line

This seems to be malformed ( add a space after 'Backport' )

v2 sent. Thanks.

Zhe

Quoted 54 lines

    +Signed-off-by: He Zhe <[email protected]>
    +---
    + tools/lib/bpf/libbpf.c | 7 ++++---
    + 1 file changed, 4 insertions(+), 3 deletions(-)
    +
    +diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
    +index dd3b2f57082d..9c98c6adb6d0 100644
    +--- a/tools/lib/bpf/libbpf.c
    ++++ b/tools/lib/bpf/libbpf.c
    +@@ -8245,7 +8245,7 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type,
    +       struct bpf_object *obj = ctx;
    +       const struct btf_type *t;
    +       struct extern_desc *ext;
    +-      char *res;
    ++      const char *res;
    +
    +       res = strstr(sym_name, ".llvm.");
    +       if (sym_type == 'd' && res)
    +@@ -11574,7 +11574,8 @@ static int avail_kallsyms_cb(unsigned long long sym_addr, char sym_type,
    +                *
    +                *   [0] fb6a421fb615 ("kallsyms: Match symbols exactly with CONFIG_LTO_CLANG")
    +                */
    +-              char sym_trim[256], *psym_trim = sym_trim, *sym_sfx;
    ++              char sym_trim[256], *psym_trim = sym_trim;
    ++              const char *sym_sfx;
    +
    +               if (!(sym_sfx = strstr(sym_name, ".llvm.")))
    +                       return 0;
    +@@ -12159,7 +12160,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] == ':')
    +--
    +2.34.1
    +
    -- 
    2.34.1


    -=-=-=-=-=-=-=-=-=-=-=-
    Links: You receive all messages sent to this group.
    View/Reply Online (#126828): https://lists.openembedded.org/g/openembedded-devel/message/126828 <https://urldefense.com/v3/__https://lists.openembedded.org/g/openembedded-devel/message/126828__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesIzpku_A$>
    Mute This Topic: https://lists.openembedded.org/mt/119225487/1997914 <https://urldefense.com/v3/__https://lists.openembedded.org/mt/119225487/1997914__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesFRJ0bCG$>
    Group Owner: [email protected] <mailto:openembedded-devel%[email protected]>
    Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub <https://urldefense.com/v3/__https://lists.openembedded.org/g/openembedded-devel/unsub__;!!AjveYdw8EvQ!fyU-8plaF3gPF7YmHPCen6iKCIBIZoQ_R9_L9KoFZOc_83Rybpe8c1G0dpdd_F-YLMUE8KAesESnBmdy$> [[email protected]]
    -=-=-=-=-=-=-=-=-=-=-=-