[3/4] ld: Fix discarded-qualifiers problems in ldlang.c

Message ID 33f90399c05753a483d91cc801953714bb7b83d9.1777074100.git.calvin@wbinvd.org
State New
Headers
Series Fix build errors due to qualifier preserving strchr() |

Commit Message

Calvin Owens April 25, 2026, 2:19 a.m. UTC
  ../../ld/ldlang.c: In function ‘archive_path’:
    ../../ld/ldlang.c:347:5: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
      347 |   p = strchr (pattern, link_info.path_separator);
          |     ^

Because the prior patch refactored input_statement_is_archive_path() to
take a constant pointer as its second argument, fix this by making the
return type of archive_path() const, and fixing up its two callers.

Signed-off-by: Calvin Owens <calvin@wbinvd.org>
---
 ld/ldlang.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Simon Marchi April 26, 2026, 2:51 a.m. UTC | #1
On 2026-04-24 22:19, Calvin Owens wrote:
>     ../../ld/ldlang.c: In function ‘archive_path’:
>     ../../ld/ldlang.c:347:5: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
>       347 |   p = strchr (pattern, link_info.path_separator);
>           |     ^
> 
> Because the prior patch refactored input_statement_is_archive_path() to
> take a constant pointer as its second argument, fix this by making the
> return type of archive_path() const, and fixing up its two callers.

There is one more to change in this file, variable `bslash` at line 10957.

Simon
  

Patch

diff --git a/ld/ldlang.c b/ld/ldlang.c
index b52ca2c4b03..1a18b8f5674 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;
@@ -423,7 +423,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)
 	{
@@ -479,7 +479,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)