| Message ID | 91ef07eb095ae29ba9bc320ca057769231202eae.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 DF5B94BB58F7 for <patchwork@sourceware.org>; Sat, 25 Apr 2026 02:20:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF5B94BB58F7 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=btvprmHY X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-dy1-x1335.google.com (mail-dy1-x1335.google.com [IPv6:2607:f8b0:4864:20::1335]) by sourceware.org (Postfix) with ESMTPS id A80E94BB3B99 for <binutils@sourceware.org>; Sat, 25 Apr 2026 02:20:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A80E94BB3B99 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 A80E94BB3B99 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777083608; cv=none; b=eJF8Hl9FYhUxhmm2EQ1bii5sZY8qFP+2WQPf1ltGKjaMX4e4lonlDIKGYzFuYtnybxzYP37ivy4cu8uHYt3DRgBxnvYJobSxdBrMF+UWECkspRbnzYZ4Y6sZ1Mr8KTAMh81+atCImHC2caNfio1w0/+qiddbAlNjL0N0Yr+mea8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777083608; c=relaxed/simple; bh=UgUED5UVYdGgDQ7r+rtQrNw5N6OTseTyCx2fWOplxYw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UR32Bar6MYkJsjHMEhmVUFlTah57Nj6Zvi25PUUDEsk5qeGds27Jn8WFjoxK48ogm+NnfQKUJaeFgiJOqXuqzfaf++KL9pW4eUjb+zUsUDwC/T/g0W3s9hcf6OM983XdGI6YPVkS3XerHBB3znzEqk7hnfNFhz3PcVVULFOEPbo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A80E94BB3B99 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-2c156c4a9efso11727172eec.1 for <binutils@sourceware.org>; Fri, 24 Apr 2026 19:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wbinvd.org; s=wbinvd; t=1777083608; x=1777688408; 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=ls8014m7pTiwuYWLcVFJRPZrU/Wb347fI033XXW5HrA=; b=btvprmHYZ7++AeOOs1+/f9/9Jv6zujo51ZiDy/j9sBGeeFAxaomEDdfNKvbVNXCmqr qknAbEF2yTHbBOII6kxsQFCaFP58sGOIBWnK/CPVtViKW4imLA5XJrI034jw8Yy0JcP+ RdNS6KvK76O9X+SlfhjStEnlryEDcUYm+x3DhQOuIlH3FG+oj4qQrn1RsSV5l0DHgO2C avezG5CRe66ttjOcJj7mPVZ75ePF/P1pKPxG4R4PfoQ7nYbuq2PT5QETLISnRrbDvPZs S9g1KQs5AL/xL7bU9298x6oVIeVa7vqwDewcj/c8F40DP2o6/gGjXwMRHi9vncY8nIfw pUbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777083608; x=1777688408; 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=ls8014m7pTiwuYWLcVFJRPZrU/Wb347fI033XXW5HrA=; b=sevTCEWVVGnTPtGaaLwjADnNNBXjhB5WipuAdy5Y65brGHRmKJVJQ6R80XQWP1Zu2B l3KOg7uBbcyP1YjVerht+1x/weaWN1KoEx1hXPUTqGvSjjthwYLR3vMdXXnjMrT1PXar QNt9/JgKIxickbb0SC9kZ6t0MvcYgw3pDx3uSXPPU78r2e99m04BrTWS8hrR7TU8yQsa 8/8iMFG8vyaCvHq7l5aDSn4t+90RqtOaOAhCEAI0n2/H3Fq93cwKMDeeXmaKau5KoFXV ku0v2wTsop39DqWWR/p7QAAz3lutGyYzmZJpRITvCJS36xxrsqFRlGGIFw7zPwZJsVzQ FCQA== X-Gm-Message-State: AOJu0Yw6ecL9l6ewv012EyfPHvPtu60aam26pPSNFKX7vUJ/+wNUlqUR fBw6wRis1aORsIQryeR6QG2CT4QELmYiwacS+BmhdoOcNf9asUpPIPHsZ0EwWCryc1baYZMZzWX DDBmV X-Gm-Gg: AeBDietE5vHKJE/f/0LTQB1tvqvFi51N8TvCf16QxAwCstFggtmW5zPeQ8kJMrrlZof bvUMpdiNWQCMmQ6sSrjvhfL6/BEPn6E/cxFIw5aph1Y9MpsJgWrUGcrgXWRN+YMvu+bbGN/LYLK 4tTAu1vnzMOXRiX87arffBypLwkoNhv6HkxNY4quQzccbwi8fH08XnI/KJWuFQP6IuruEKXXzYt rWO64y+7GcftMVyALlCzfBnajKnObgioCXP4ZM8diD7v7U3FuR8oFLwb9Of8kN6je7Rb4LhykEz HfqBcBlNy9mwSv3tWkOiRn2tbpJSP7PZSam+qZWktxDSgBrqCtm2/34ISfaTrI0OKglNG/g0LVZ k3QJfiTWokHNToPSBydXxCbC0h3trgiUZPVJoP3NO4IshaaBfRzF4vZhUACKvCNBzzKo+lKeeVc /+43a9gjnUfF0r0N4HkyRKfzyZ4DSaTj71eoAO X-Received: by 2002:a05:7300:fb94:b0:2c4:61be:1d33 with SMTP id 5a478bee46e88-2e464eaa230mr17321926eec.6.1777083607662; Fri, 24 Apr 2026 19:20:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 19:20:07 -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 2/4] ld: Refactor input_statement_is_archive_path() to not touch its argument Date: Fri, 24 Apr 2026 19:19:45 -0700 Message-ID: <91ef07eb095ae29ba9bc320ca057769231202eae.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-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 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
This is prep work for the next patch, no functional change intended.
Signed-off-by: Calvin Owens <calvin@wbinvd.org>
---
ld/ldlang.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
Comments
On Fri, Apr 24, 2026 at 07:19:45PM -0700, Calvin Owens wrote: > + char *tmp = stat_strdup (file_spec); > + > + tmp[sep - file_spec] = 0; > + match = name_match (tmp, aname) == 0; > + stat_free (tmp); Let's not make an unnecessary copy. I'm going to apply the following. ---- Assign strchr return to a const char* to match its arg in a couple of places. archive_path now returns a const char*, and input_statement_is_archive_path now has a const char* sep arg. If you follow where these args come from in ldgram.y it can be seen that they are in fact in writable memory, so it isn't necessary to copy file_spec to poke in a zero which is restored before the function returns. Signed-off-by: Calvin Owens <calvin@wbinvd.org> Signed-off-by: Alan Modra <amodra@gmail.com> diff --git a/ld/ldlang.c b/ld/ldlang.c index dec3d586671..48dd33a49bb 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -337,10 +337,10 @@ stat_ldirname (const char *name) /* If PATTERN is of the form archive:file, return a pointer to the separator. If not, return NULL. */ -static char * +static const char * archive_path (const char *pattern) { - char *p = NULL; + const char *p = NULL; if (link_info.path_separator == 0) return p; @@ -362,7 +362,7 @@ archive_path (const char *pattern) return whether F matches FILE_SPEC. */ static bool -input_statement_is_archive_path (const char *file_spec, char *sep, +input_statement_is_archive_path (const char *file_spec, const char *sep, lang_input_statement_type *f) { bool match = false; @@ -377,9 +377,10 @@ input_statement_is_archive_path (const char *file_spec, char *sep, if (sep != file_spec) { const char *aname = bfd_get_filename (f->the_bfd->my_archive); - *sep = 0; + /* SEP which points into FILE_SPEC is in writable memory. */ + *(char *) sep = 0; match = name_match (file_spec, aname) == 0; - *sep = link_info.path_separator; + *(char *) sep = link_info.path_separator; } } return match; @@ -421,7 +422,7 @@ walk_wild_file_in_exclude_list (struct name_list *exclude_list, list_tmp; list_tmp = list_tmp->next) { - char *p = archive_path (list_tmp->name); + const char *p = archive_path (list_tmp->name); if (p != NULL) { @@ -477,7 +478,7 @@ walk_wild_section_match (lang_wild_statement_type *ptr, { struct wildcard_list *sec; const char *file_spec = ptr->filename; - char *p; + const char *p; /* Check if filenames match. */ if (file_spec == NULL) @@ -10946,7 +10947,7 @@ cmdline_fopen_temp (const char *path, const char *target, #ifdef HAVE_DOS_BASED_FILE_SYSTEM { /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ - char *bslash = strrchr (path, '\\'); + const char *bslash = strrchr (path, '\\'); if (slash == NULL || (bslash != NULL && bslash > slash)) slash = bslash;
On Saturday 05/02 at 17:36 +0930, Alan Modra wrote: > On Fri, Apr 24, 2026 at 07:19:45PM -0700, Calvin Owens wrote: > > + char *tmp = stat_strdup (file_spec); > > + > > + tmp[sep - file_spec] = 0; > > + match = name_match (tmp, aname) == 0; > > + stat_free (tmp); > > Let's not make an unnecessary copy. I'm going to apply the following. > ---- > > Assign strchr return to a const char* to match its arg in a couple of > places. archive_path now returns a const char*, and > input_statement_is_archive_path now has a const char* sep arg. If > you follow where these args come from in ldgram.y it can be seen that > they are in fact in writable memory, so it isn't necessary to copy > file_spec to poke in a zero which is restored before the function > returns. > > Signed-off-by: Calvin Owens <calvin@wbinvd.org> I've had a busy week, apologies I didn't get a chance to refresh this. It's very generous of you to credit me, but not necessary :) Cheers, Calvin > Signed-off-by: Alan Modra <amodra@gmail.com> > > diff --git a/ld/ldlang.c b/ld/ldlang.c > index dec3d586671..48dd33a49bb 100644 > --- a/ld/ldlang.c > +++ b/ld/ldlang.c > @@ -337,10 +337,10 @@ stat_ldirname (const char *name) > /* If PATTERN is of the form archive:file, return a pointer to the > separator. If not, return NULL. */ > > -static char * > +static const char * > archive_path (const char *pattern) > { > - char *p = NULL; > + const char *p = NULL; > > if (link_info.path_separator == 0) > return p; > @@ -362,7 +362,7 @@ archive_path (const char *pattern) > return whether F matches FILE_SPEC. */ > > static bool > -input_statement_is_archive_path (const char *file_spec, char *sep, > +input_statement_is_archive_path (const char *file_spec, const char *sep, > lang_input_statement_type *f) > { > bool match = false; > @@ -377,9 +377,10 @@ input_statement_is_archive_path (const char *file_spec, char *sep, > if (sep != file_spec) > { > const char *aname = bfd_get_filename (f->the_bfd->my_archive); > - *sep = 0; > + /* SEP which points into FILE_SPEC is in writable memory. */ > + *(char *) sep = 0; > match = name_match (file_spec, aname) == 0; > - *sep = link_info.path_separator; > + *(char *) sep = link_info.path_separator; > } > } > return match; > @@ -421,7 +422,7 @@ walk_wild_file_in_exclude_list (struct name_list *exclude_list, > list_tmp; > list_tmp = list_tmp->next) > { > - char *p = archive_path (list_tmp->name); > + const char *p = archive_path (list_tmp->name); > > if (p != NULL) > { > @@ -477,7 +478,7 @@ walk_wild_section_match (lang_wild_statement_type *ptr, > { > struct wildcard_list *sec; > const char *file_spec = ptr->filename; > - char *p; > + const char *p; > > /* Check if filenames match. */ > if (file_spec == NULL) > @@ -10946,7 +10947,7 @@ cmdline_fopen_temp (const char *path, const char *target, > #ifdef HAVE_DOS_BASED_FILE_SYSTEM > { > /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ > - char *bslash = strrchr (path, '\\'); > + const char *bslash = strrchr (path, '\\'); > > if (slash == NULL || (bslash != NULL && bslash > slash)) > slash = bslash; > > -- > Alan Modra
diff --git a/ld/ldlang.c b/ld/ldlang.c index d75f9df4d43..b52ca2c4b03 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -362,7 +362,7 @@ archive_path (const char *pattern) return whether F matches FILE_SPEC. */ static bool -input_statement_is_archive_path (const char *file_spec, char *sep, +input_statement_is_archive_path (const char *file_spec, const char *sep, lang_input_statement_type *f) { bool match = false; @@ -377,9 +377,11 @@ input_statement_is_archive_path (const char *file_spec, char *sep, if (sep != file_spec) { const char *aname = bfd_get_filename (f->the_bfd->my_archive); - *sep = 0; - match = name_match (file_spec, aname) == 0; - *sep = link_info.path_separator; + char *tmp = stat_strdup (file_spec); + + tmp[sep - file_spec] = 0; + match = name_match (tmp, aname) == 0; + stat_free (tmp); } } return match;