[2.46,PATCHES] Fix build under glibc 2.43

Message ID CAMe9rOqx910Ha3=3rcULpL7iGPqp7CEWi5N6Q+NTCkJDZvt2AA@mail.gmail.com
State New
Headers
Series [2.46,PATCHES] Fix build under glibc 2.43 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

H.J. Lu May 4, 2026, 9:59 p.m. UTC
  <features.h> from glibc 2.43 has

/* If _GNU_SOURCE was defined by the user, turn on all the other features.  */
#ifdef _GNU_SOURCE
# undef  _ISOC95_SOURCE
# define _ISOC95_SOURCE 1
# undef  _ISOC99_SOURCE
# define _ISOC99_SOURCE 1
# undef  _ISOC11_SOURCE
# define _ISOC11_SOURCE 1
# undef  _ISOC23_SOURCE
# define _ISOC23_SOURCE 1

which triggers

/export/gnu/import/git/gitlab/x86-binutils-release/gprof/source.c: In
function ‘annotate_source’:
/export/gnu/import/git/gitlab/x86-binutils-release/gprof/source.c:126:21:
error: assignment discards ‘const’ qualifier from pointer target type
[-Werror=discarded-qualifiers]
  126 |           name_only = strrchr (sf->name, '/');
      |                     ^
cc1: all warnings being treated as errors

since <string.h> has

# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
#  define strrchr(S, C)                                         \
  __glibc_const_generic (S, const char *, strrchr (S, C))
# endif
#endif

Backport the following patches from master branch:

bfbfc5338fe Fix discarded-qualifiers problems in ldlang.c
f4e1e879c3b ld: Fix calls to strchr that discard or use wrong const qualifiers
23cffbed18e binutils: fix C23 -Wdiscarded-qualifiers errors
742891031fb Fix the strrchr error for DOS based filesystem
2c40bfc752b gprof: Fix strchr discarded qualifier call

to fix the binutils 2.46 build under glibc 2.43.

Any comments?

H.J.
  

Comments

Sam James May 7, 2026, 10:38 a.m. UTC | #1
"H.J. Lu" <hjl.tools@gmail.com> writes:

> <features.h> from glibc 2.43 has
>
> /* If _GNU_SOURCE was defined by the user, turn on all the other features.  */
> #ifdef _GNU_SOURCE
> # undef  _ISOC95_SOURCE
> # define _ISOC95_SOURCE 1
> # undef  _ISOC99_SOURCE
> # define _ISOC99_SOURCE 1
> # undef  _ISOC11_SOURCE
> # define _ISOC11_SOURCE 1
> # undef  _ISOC23_SOURCE
> # define _ISOC23_SOURCE 1
>
> which triggers
>
> /export/gnu/import/git/gitlab/x86-binutils-release/gprof/source.c: In
> function ‘annotate_source’:
> /export/gnu/import/git/gitlab/x86-binutils-release/gprof/source.c:126:21:
> error: assignment discards ‘const’ qualifier from pointer target type
> [-Werror=discarded-qualifiers]
>   126 |           name_only = strrchr (sf->name, '/');
>       |                     ^
> cc1: all warnings being treated as errors
>
> since <string.h> has
>
> # if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
> #  define strrchr(S, C)                                         \
>   __glibc_const_generic (S, const char *, strrchr (S, C))
> # endif
> #endif
>
> Backport the following patches from master branch:
>
> bfbfc5338fe Fix discarded-qualifiers problems in ldlang.c
> f4e1e879c3b ld: Fix calls to strchr that discard or use wrong const qualifiers
> 23cffbed18e binutils: fix C23 -Wdiscarded-qualifiers errors
> 742891031fb Fix the strrchr error for DOS based filesystem
> 2c40bfc752b gprof: Fix strchr discarded qualifier call
>
> to fix the binutils 2.46 build under glibc 2.43.
>
> Any comments?

I think it's a good idea.

Nick, I'd like to make a 2.46.1 release with these patches
because of the -Werror thing with 2.46.0
(https://inbox.sourceware.org/binutils/c4e611d0-2ef2-4495-8623-7ec82df3f101@gmail.com/).

Is that OK with you?

> [...]

sam
  
Nick Clifton May 7, 2026, 11:37 a.m. UTC | #2
Hi Sam,

> Nick, I'd like to make a 2.46.1 release with these patches
> because of the -Werror thing with 2.46.0
> (https://inbox.sourceware.org/binutils/c4e611d0-2ef2-4495-8623-7ec82df3f101@gmail.com/).
> 
> Is that OK with you? 

Certainly, please go ahead.

Cheers
   Nick
  

Patch

From 9d6f47016b14583db5221268b8045888426cb8c5 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Fri, 13 Feb 2026 14:17:40 -0500
Subject: [PATCH 3/5] binutils: fix C23 -Wdiscarded-qualifiers errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When compiling with gcc 15, I get these:

      CC       prdbg.o
    /home/simark/src/binutils-gdb/binutils/prdbg.c: In function ‘tg_start_function’:
    /home/simark/src/binutils-gdb/binutils/prdbg.c:2658:11: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
     2658 |       sep = strchr (name, '(');
          |           ^
    cc1: all warnings being treated as errors
    make[2]: *** [Makefile:1220: prdbg.o] Error 1
      CC       addr2line.o
    /home/simark/src/binutils-gdb/binutils/addr2line.c: In function ‘translate_addresses’:
    /home/simark/src/binutils-gdb/binutils/addr2line.c:390:21: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
      390 |                   h = strrchr (filename, '/');
          |                     ^
    cc1: all warnings being treated as errors
    make[2]: *** [Makefile:1220: addr2line.o] Error 1
      CC       nm.o
    /home/simark/src/binutils-gdb/binutils/nm.c: In function ‘print_symname’:
    /home/simark/src/binutils-gdb/binutils/nm.c:689:21: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
      689 |       char *atver = strchr (name, '@');
          |                     ^~~~~~
    cc1: all warnings being treated as errors

I think they are related to the fact that strchr having changed to
return const when passed a const.

This partially fixes PR binutils/34125.

Change-Id: Idb829916378f0a18e717d1e80414aaa5eba4f7f0
(cherry picked from commit 9cb12adfb54bc3dabf4ee00296064245eb7660ef)
---
 binutils/addr2line.c | 2 +-
 binutils/nm.c        | 2 +-
 binutils/prdbg.c     | 8 +++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/binutils/addr2line.c b/binutils/addr2line.c
index 141a7099de4..f8c110f532f 100644
--- a/binutils/addr2line.c
+++ b/binutils/addr2line.c
@@ -385,7 +385,7 @@  translate_addresses (bfd *abfd, asection *section)
 
               if (base_names && filename != NULL)
                 {
-                  char *h;
+                  const char *h;
 
                   h = strrchr (filename, '/');
                   if (h != NULL)
diff --git a/binutils/nm.c b/binutils/nm.c
index 3aef8ebe098..c5f7e68e9df 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -686,7 +686,7 @@  print_symname (const char *form, struct extended_symbol_info *info,
   if (!with_symbol_versions
       && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
     {
-      char *atver = strchr (name, '@');
+      const char *atver = strchr (name, '@');
 
       if (atver)
 	{
diff --git a/binutils/prdbg.c b/binutils/prdbg.c
index 287083df1b9..ff24eac54fb 100644
--- a/binutils/prdbg.c
+++ b/binutils/prdbg.c
@@ -2642,22 +2642,24 @@  tg_start_function (void *p, const char *name, bool global)
   if (dname != NULL)
     {
       char *sep;
+      char *mutable_name;
       sep = strstr (dname, "::");
       if (sep)
 	{
 	  info->stack->method = dname;
 	  dname = NULL;
 	  *sep = 0;
-	  name = sep + 2;
+	  mutable_name = sep + 2;
 	}
       else
 	{
 	  info->stack->method = xstrdup ("");
-	  name = dname;
+	  mutable_name = dname;
 	}
-      sep = strchr (name, '(');
+      sep = strchr (mutable_name, '(');
       if (sep)
 	*sep = 0;
+      name = mutable_name;
       /* Obscure functions as type_info function.  */
     }
 
-- 
2.54.0