arc gas: don't use X_md as input to expression()

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.
This commit is contained in:
Alan Modra
2025-10-04 08:36:22 +09:30
parent 32a7293a02
commit 4208f50c6d

View 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)
{