]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: Fix calls to strchr that discard or use wrong const qualifiers
authorMark Wielaard <mark@klomp.org>
Sat, 2 May 2026 16:56:52 +0000 (18:56 +0200)
committerMark Wielaard <mark@klomp.org>
Sun, 3 May 2026 12:15:41 +0000 (14:15 +0200)
* ld/emultempl/pe.em (pe_fixup_stdcalls): Make at a const char *.
(gldEMULATION_NAME_after_open): Make pnt a const char *.
(gldEMULATION_NAME_place_orphan): Make dollar a const char *.
* ld/emultempl/pep.em (pep_fixup_stdcalls): Make at a
const char *. Introduce at2 as non-const char *.
(gldEMULATION_NAME_after_open): Make pnt a const char *.
(gldEMULATION_NAME_place_orphan): Make dollar a const char *.
* ld/emultempl/spuelf.em (spu_elf_load_ovl_mgr): Make p a
const char *. Introduce np as char *.
* ld/ldelf.c (ldelf_search_needed): Call strchr on freeme, so
slash is non-const, then assign freeme to replacement.

ld/emultempl/beos.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/emultempl/spuelf.em
ld/ldelf.c

index e456112fc54e37492342d0c0b28d0562e72aa1a3..c027a7536dc841f52b04553746be21f90e7d3df1 100644 (file)
@@ -554,7 +554,7 @@ sort_sections (lang_statement_union_type *s)
                 the linker handle the rest).  */
              if (sec->spec.name != NULL)
                {
-                 char *q = strchr (sec->spec.name, '\$');
+                 const char *q = strchr (sec->spec.name, '\$');
 
                  if (q != NULL
                      && (q[1] == '\0'
index 46abac78946938187b8fccfffe70b5582536f3d0..07ef2ca595314b58902462ab942ad63a19481075 100644 (file)
@@ -1149,7 +1149,7 @@ pe_fixup_stdcalls (void)
     if (undef->type == bfd_link_hash_undefined)
       {
        const char * name = undef->root.string;
-       char * at;
+       const char * at;
        int lead_at = (*name == '@');
 
        if (lead_at)
@@ -1750,7 +1750,7 @@ gld${EMULATION_NAME}_after_open (void)
       {
        if (is->the_bfd->my_archive)
          {
-           char *pnt;
+           const char *pnt;
 
            /* Microsoft import libraries may contain archive members for
               one or more DLLs, together with static object files.
@@ -2146,7 +2146,7 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
                                   int constraint)
 {
   const char *orig_secname = secname;
-  char *dollar = NULL;
+  const char *dollar = NULL;
   lang_output_section_statement_type *os;
   lang_statement_list_type add_child;
   lang_output_section_statement_type *match_by_name = NULL;
index 280949b6e516cdc6b1e509fcd3f52415ef082773..25ce3963b3639e61a6ceb145201f54cca101725c 100644 (file)
@@ -1089,7 +1089,7 @@ pep_fixup_stdcalls (void)
   for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
     if (undef->type == bfd_link_hash_undefined)
       {
-       char* at = strchr (undef->root.string, '@');
+       const char* at = strchr (undef->root.string, '@');
        int lead_at = (*undef->root.string == '@');
        if (lead_at)
          at = strchr (undef->root.string + 1, '@');
@@ -1098,12 +1098,13 @@ pep_fixup_stdcalls (void)
            /* The symbol is a stdcall symbol, so let's look for a
               cdecl symbol with the same name and resolve to that.  */
            char *cname = xstrdup (undef->root.string);
+           char *at2;
 
            if (lead_at)
              *cname = '_';
-           at = strchr (cname, '@');
-           if (at)
-             *at = 0;
+           at2 = strchr (cname, '@');
+           if (at2)
+             *at2 = 0;
            sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
 
            if (sym && sym->type == bfd_link_hash_defined)
@@ -1737,7 +1738,7 @@ gld${EMULATION_NAME}_after_open (void)
       {
        if (is->the_bfd->my_archive)
          {
-           char *pnt;
+           const char *pnt;
 
            /* Microsoft import libraries may contain archive members for
               one or more DLLs, together with static object files.
@@ -1986,7 +1987,7 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
                                    int constraint)
 {
   const char *orig_secname = secname;
-  char *dollar = NULL;
+  const char *dollar = NULL;
   lang_output_section_statement_type *os;
   lang_statement_list_type add_child;
   lang_output_section_statement_type *match_by_name = NULL;
index ae9d6e31f5ce6fb4400aea3efc5c61d4c4d631f2..98e5d7636bd00956db3463840e7422f53d7d98ee 100644 (file)
@@ -235,14 +235,14 @@ spu_elf_load_ovl_mgr (void)
                    if (!lang_output_section_find (oname))
                      {
                        lang_output_section_statement_type *os = NULL;
-                       char *p = strchr (oname + 1, '.');
+                       const char *p = strchr (oname + 1, '.');
                        if (p != NULL)
                          {
                            size_t len = p - oname;
-                           p = memcpy (xmalloc (len + 1), oname, len);
-                           p[len] = '\0';
-                           os = lang_output_section_find (p);
-                           free (p);
+                           char *np = memcpy (xmalloc (len + 1), oname, len);
+                           np[len] = '\0';
+                           os = lang_output_section_find (np);
+                           free (np);
                          }
                        if (os != NULL)
                          oname = os->name;
index 15d4b576bc03db3fb9ceaa6875ddbbb3d959d597..eec13501ef7edfb65433b0dbbe831eb31d7d38b3 100644 (file)
@@ -534,9 +534,9 @@ ldelf_search_needed (const char *path, struct dt_needed *n, int force,
                                  replacement, rep_len + 1);
                        }
 
-                     replacement = freeme;
-                     if ((slash = strrchr (replacement, '/')) != NULL)
+                     if ((slash = strrchr (freeme, '/')) != NULL)
                        * slash = 0;
+                     replacement = freeme;
                    }
                }
              break;
@@ -794,7 +794,7 @@ ldelf_parse_ld_so_conf_include (struct ldelf_ld_so_conf *info,
 
   if (pattern[0] != '/')
     {
-      char *p = strrchr (filename, '/');
+      const char *p = strrchr (filename, '/');
       size_t patlen = strlen (pattern) + 1;
 
       newp = xmalloc (p - filename + 1 + patlen);