]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
arc gas: don't use X_md as input to expression()
authorAlan Modra <amodra@gmail.com>
Fri, 3 Oct 2025 23:06:22 +0000 (08:36 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 4 Oct 2025 00:09:02 +0000 (09:39 +0930)
tc-arc.c:tokenize_arguments tweaks expression() parsing, controlling
whether arc_parse_name does anything by setting X_op and X_md in the
expressionS argument passed to expression().  I want to change expr()
to always fully initialise its result, and that means either a special
expression initialiser for arc, or controlling arc_parse_name by some
other means.  Since arc_parse_name already tests "assembling_insn" and
no other code does, change "assembling_insn" to directly control
arc_parse_name.  Doing it this way also stops a possible uninitialised
access to right.X_op from expr() in arc_parse_name with current gas.
The next patch in this series will also stop such uninitialised
accesses.

* config/tc-arc.c (assembling_insn): Update comment.
(tokenize_arguments): Don't set X_op and X_md to control
expression(), instead just use assembling_insn.
(md_operand): Similarly.
(arc_parse_name): Don't test X_op and X_md.
(md_assemble): Don't set assembling_insn here.

gas/config/tc-arc.c

index 4c27c60c0e34829e66783ba6f5246078f838e3ce..be1c79ac07e920451b4804b0b19afef18decd164 100644 (file)
@@ -686,7 +686,7 @@ const unsigned arc_num_relaxable_ins = ARRAY_SIZE (arc_relaxable_insns);
 /* Pre-defined "_GLOBAL_OFFSET_TABLE_".  */
 symbolS * GOT_symbol = 0;
 
-/* Set to TRUE when we assemble instructions.  */
+/* Set to TRUE for a special parsing action when assembling instructions.  */
 static bool assembling_insn = false;
 
 /* List with attributes set explicitly.  */
@@ -1275,9 +1275,8 @@ tokenize_arguments (char *str,
 
          /* Parse @label.  */
          input_line_pointer++;
-         tok->X_op = O_symbol;
-         tok->X_md = O_absent;
          expression (tok);
+         tok->X_md = O_absent;
 
          if (*input_line_pointer == '@')
            parse_reloc_symbol (tok);
@@ -1304,9 +1303,11 @@ tokenize_arguments (char *str,
          if ((saw_arg && !saw_comma) || num_args == ntok)
            goto err;
 
-         tok->X_op = O_absent;
-         tok->X_md = O_absent;
+         /* Tell arc_parse_name to do its job.  */
+         assembling_insn = true;
          expression (tok);
+         assembling_insn = false;
+         tok->X_md = O_absent;
 
          /* Legacy: There are cases when we have
             identifier@relocation_type, if it is the case parse the
@@ -2522,9 +2523,6 @@ md_assemble (char *str)
   opnamelen = strspn (str, "abcdefghijklmnopqrstuvwxyz_0123456789");
   opname = xmemdup0 (str, opnamelen);
 
-  /* Signalize we are assembling the instructions.  */
-  assembling_insn = true;
-
   /* Tokenize the flags.  */
   if ((nflg = tokenize_flags (str + opnamelen, flags, MAX_INSN_FLGS)) == -1)
     {
@@ -2548,7 +2546,6 @@ md_assemble (char *str)
 
   /* Finish it off.  */
   assemble_tokens (opname, tok, ntok, flags, nflg);
-  assembling_insn = false;
 }
 
 /* Callback to insert a register into the hash table.  */
@@ -3386,9 +3383,8 @@ md_operand (expressionS *expressionP)
   if (*p == '@')
     {
       input_line_pointer++;
-      expressionP->X_op = O_symbol;
-      expressionP->X_md = O_absent;
       expression (expressionP);
+      expressionP->X_md = O_absent;
     }
 }
 
@@ -3406,10 +3402,6 @@ arc_parse_name (const char *name,
   if (!assembling_insn)
     return false;
 
-  if (e->X_op == O_symbol
-      && e->X_md == O_absent)
-    return false;
-
   sym = str_hash_find (arc_reg_hash, name);
   if (sym)
     {