[binutils-gdb] Fix discarded-qualifiers problems in ldlang.c

Alan Modra amodra@sourceware.org
Sat May 2 08:07:11 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=65cd0d66a647f14719e69bd19f34dc98bdb7e635

commit 65cd0d66a647f14719e69bd19f34dc98bdb7e635
Author: Calvin Owens <calvin@wbinvd.org>
Date:   Sat May 2 10:03:21 2026 +0930

    Fix discarded-qualifiers problems in ldlang.c
    
    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:
---
 ld/ldlang.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

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;


More information about the Binutils-cvs mailing list