| Message ID | 003fed7e07f6f9ed6a8c365e31325162a840fa03.1777074100.git.calvin@wbinvd.org |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 121984BB5888 for <patchwork@sourceware.org>; Sat, 25 Apr 2026 02:20:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 121984BB5888 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=wbinvd.org header.i=@wbinvd.org header.a=rsa-sha256 header.s=wbinvd header.b=TPoVcuM0 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-dy1-x1333.google.com (mail-dy1-x1333.google.com [IPv6:2607:f8b0:4864:20::1333]) by sourceware.org (Postfix) with ESMTPS id B884D4BB3B8E for <binutils@sourceware.org>; Sat, 25 Apr 2026 02:20:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B884D4BB3B8E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=wbinvd.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B884D4BB3B8E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777083607; cv=none; b=w0CLq4ARbd9jJXh4h1uIZyAifUUcp7L3nUQteNsZVMo2ax8nbp8lWzcB4382HCXzeQmVGzrxvXHna6fwiPMAIjD+lfE7035smH3gBMpWMkzur5nJlQ8biDqJElYfEl4FGgwrk82O+L6ERG2NCOp3QhVofYfss6GWdcNP8pzFvEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777083607; c=relaxed/simple; bh=XhwbLSE2mAuhRG3W+Oe4gKwzhbvpQ7Ju0UyeUEvzP50=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hg9ld2QSSUYLMyT64ZK81/jOInIJa7ILcvrDD8dBYIW/Pdi++z/v42IV3Yme67VfwSf5Nx+HEkijixtQgaZRZiUItDYKr+9vJUkgnnHLG5Xj+VDCeeG0GJ7u9o8f9IBiQY4JgfYeutE/7gEIccRKgTUugQ+KsO6hLqkNGdHyH9c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B884D4BB3B8E Received: by mail-dy1-x1333.google.com with SMTP id 5a478bee46e88-2c156c4a9efso11727162eec.1 for <binutils@sourceware.org>; Fri, 24 Apr 2026 19:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wbinvd.org; s=wbinvd; t=1777083607; x=1777688407; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VgFYsObdqiYXwBg4S3BjjKpI4izuw9XzgaNqwwcZDvM=; b=TPoVcuM0eSqjiyLVE4YY+wiKZTqRVI4a0UUnKehDa73Y1PLTlOySQnm1d8DVBd/XiR SLtjWL3NyRadvMv5vMXMkMxedJcHMk6SJKpA7TC7F0ou/WaGpdsZoUstRtypFuySO3Zm mJ0yhCRwNSFhDrQQlWeoP63hN9m2z0HMVYDIP+ul+z4Dnusz0/sfS2OjBlKJT5TDKmS/ s0Wq84f7H/s0oI/fsS2gbOmNmfaC+9VDDc8UbQ8MJioJdWsxvbbqZDmP7Ln3FGHNa87j 4Yqrp4U8JGln80GCGU167Y2SF4I1UQR28lg0rJa3K/mIV4mRSqVUvA/KcmMCq61UN31y INqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777083607; x=1777688407; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VgFYsObdqiYXwBg4S3BjjKpI4izuw9XzgaNqwwcZDvM=; b=jw13sdfivDl6SIw6Xa8E+bJ46oL6R1puyoLLyw4vfUhRD/TDXUVEfa6X7liXpCi7Ea xx+VwlsB4/z6AaCfl2fKzXDQzWIrdQa9mCHtTvPfR3GFgUeouuEP1Kqwo19z/gxau4WB wZc0V+BuFjgnghmW//apcXxjwkeAszoHj25W3Ovn+E0t8oEHFdcaBtkmrOc9K/WHaYju 12viQz+6bYdVeNGtm/zPYxWPuQw9DBQ52JGAbibPmJOT1c2jrvV41wp7FfVdpcF9jtdF U9aR7pn6ShxT5flc4ivMVE7JulniYY2wqWF/+rUt+ca/81wvuHD2vsFbjdvXfwzbgFPD 5PKA== X-Gm-Message-State: AOJu0YxbMdzIMNoXi984BSmLFP0Jyyf2/TMOxl4eaBlpvFGJk32E2J34 RqcdjHe08yshuM/UrYEVfK5tCj1j7L9cAoAcXAkcod0oMzzeHuteCtCpo+MFLUu/UgrlI6oCT93 6tA+U X-Gm-Gg: AeBDies/aKEPItXRolKFUtgIWl1savu+ZnMwMvWYzQFXCTZL066DmcE71Tb3GrqlH/M CSpE2j6vJ/x7AJEcKOV87FJCydBV2SIhdpr9/R6Xi8n1xUhVOvp4s8zMNvI5prJaQhZU3wvcnQF ZBfz19BaHwYUGclbUlKPEJ+xP5KXYp6qtjZmfleiyHoHdcugCyKDvVpE19GaNHjoSCIIGlWmpqt wXiRxvrP6whCuEjzo4k4TdwGW6MQcdFzXJWZgaNSbNtY7FjlW6xMshTQG6eRLlcYslTAB3g4jPd otKQbmSBUmGZqffiW1A8tvOLlEVKqeOctd0UkYYesLgBdgEW9t55DkzMorJiYaC99CEJy1e80F0 KbQ6qn7CNjVYqWOUijiS0r/xACSGJlaoVDdf7gVysbiYV/RNT3RyrWzQ2+ZYSN0WpBhpdMt+Q/3 wiB9wYjqJpPtC/8FCeE3kTQQDXUtOPUmA+Il/T X-Received: by 2002:a05:7300:5ba1:b0:2dd:8ac2:9f7a with SMTP id 5a478bee46e88-2eada6d6539mr3738694eec.11.1777083606673; Fri, 24 Apr 2026 19:20:06 -0700 (PDT) Received: from mozart.vkv.me ([2001:5a8:468b:d015:1989:57e8:b4c5:739f]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2e53d8b944bsm34587278eec.28.2026.04.24.19.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 19:20:06 -0700 (PDT) From: Calvin Owens <calvin@wbinvd.org> To: binutils@sourceware.org Cc: simon.marchi@polymtl.ca, keiths@redhat.com, calvin@wbinvd.org Subject: [PATCH 1/4] gprof: Fix discarded-qualifiers problems in source.c Date: Fri, 24 Apr 2026 19:19:44 -0700 Message-ID: <003fed7e07f6f9ed6a8c365e31325162a840fa03.1777074100.git.calvin@wbinvd.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <cover.1777074100.git.calvin@wbinvd.org> References: <cover.1777074100.git.calvin@wbinvd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
Fix build errors due to qualifier preserving strchr()
|
|
Commit Message
Calvin Owens
April 25, 2026, 2:19 a.m. UTC
../../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(-)
Comments
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; > > @@ -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. Simon
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
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; @@ -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; } #endif if (name_only)