[PATCH 1/4] gprof: Fix discarded-qualifiers problems in source.c
Mark Wielaard
mark@klomp.org
Sun May 3 12:25:04 GMT 2026
Hi Calvin,
On Sat, Apr 25, 2026 at 10:35:04PM -0400, Simon Marchi wrote:
>
>
> On 2026-04-24 22:19, Calvin Owens wrote:
> > ../../gprof/source.c: In function ‘annotate_source’:
> > ../../gprof/source.c:126:21: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
> > 126 | name_only = strrchr (sf->name, '/');
> > | ^
> >
> > Fix this and the similar problem immediately below it by declaring the
> > local pointer varaibles as const, since they are not modified.
> >
> > Signed-off-by: Calvin Owens <calvin@wbinvd.org>
> > ---
> > gprof/source.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/gprof/source.c b/gprof/source.c
> > index 494f6ecc9b2..322d1fe25a7 100644
> > --- a/gprof/source.c
> > +++ b/gprof/source.c
> > @@ -98,7 +98,8 @@ annotate_source (Source_File *sf, unsigned int max_width,
> > bool new_line;
> > char buf[8192];
> > char *fname;
> > - char *annotation, *name_only;
> > + char *annotation;
> > + const char *name_only;
> > FILE *ifp, *ofp;
> > Search_List_Elem *sle = src_search_list.head;
Sorry, I didn't see you already proposed a fix for this.
I think this part is correct and I reinvented it here:
https://inbox.sourceware.org/binutils/20260502170132.3303884-2-mark@klomp.org/
> > @@ -126,11 +127,11 @@ annotate_source (Source_File *sf, unsigned int max_width,
> > name_only = strrchr (sf->name, '/');
> > #ifdef HAVE_DOS_BASED_FILE_SYSTEM
> > {
> > - char *bslash = strrchr (sf->name, '\\');
> > + const char *bslash = strrchr (sf->name, '\\');
> > if (name_only == NULL || (bslash != NULL && bslash > name_only))
> > name_only = bslash;
> > if (name_only == NULL && sf->name[0] != '\0' && sf->name[1] == ':')
> > - name_only = (char *)sf->name + 1;
> > + name_only = (const char *)sf->name + 1;
>
> I think that you can just remove this cast to `const char *`, since
> `sf->name` is already a `const char *`.
>
> There is another spot to change, variable `bslash` at line 187 of the
> same file. I found this by inverting all #if conditions just to
> build-test.
I believe H.J. fixed this here:
https://inbox.sourceware.org/binutils/CAMe9rOpJsbA5QZssE9ejG5WCuw5hU+sQyvgcMSnDjqH-Yv22XQ@mail.gmail.com/
But the first part should still go in to fix the build with GCC 16.1
and glibc 2.43.
Cheers,
Mark
More information about the Binutils
mailing list