diff options
author | Jan Beulich <jbeulich@suse.com> | 2022-01-04 10:05:17 +0100 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2022-01-04 10:05:17 +0100 |
commit | 5ed4d49d107c46670a7994711f0284776a35284e (patch) | |
tree | d883166be8b96d7aa83f6c1f7dfc0d1ebfbc6c53 /gas/expr.c | |
parent | 79541a6d9220e800ebc5278594105982d6e1d80c (diff) | |
download | gdb-5ed4d49d107c46670a7994711f0284776a35284e.zip gdb-5ed4d49d107c46670a7994711f0284776a35284e.tar.gz gdb-5ed4d49d107c46670a7994711f0284776a35284e.tar.bz2 |
gas: rework handling of backslashes in quoted symbol names
Strange effects can result from the present handling, e.g.:
.if 1
"backslash\\":
.endif
yields first (correctly) "missing closing `"'" but then also "invalid
character '\' in mnemonic" and further "end of file inside conditional".
Symbols names ending in \ are in principle not expressable with that
scheme.
Instead of recording whether a backslash was seen, inspect the
subsequent character right away. Only accept \\ (meaning a single
backslash in the resulting symbol name) and \" (meaning an embedded
double quote in the resulting symbol name) for now, warning about any
other combination.
While perhaps not necessary immediately, also permit concatenated
strings to form a symbol name. This may become useful if going forward
we would want to support \<octal> or \x<hex> sequences, where closing
and re-opening quotes can be useful to delimit such sequences.
The ELF "Multibyte symbol names" test gets switched away from using
.set, as that would now also mean excluding nios2 and pru. By using
.equiv instead, even the existing #notarget can be dropped. (For h8300
the .section directive additionally needs attributes specified, to avoid
a target specific warning.)
Diffstat (limited to 'gas/expr.c')
-rw-r--r-- | gas/expr.c | 50 |
1 files changed, 42 insertions, 8 deletions
@@ -2400,18 +2400,52 @@ get_symbol_name (char ** ilp_return) } else if (c == '"') { - bool backslash_seen; + char *dst = input_line_pointer; * ilp_return = input_line_pointer; - do + for (;;) { - backslash_seen = c == '\\'; - c = * input_line_pointer ++; - } - while (c != 0 && (c != '"' || backslash_seen)); + c = *input_line_pointer++; + + if (c == 0) + { + as_warn (_("missing closing '\"'")); + break; + } - if (c == 0) - as_warn (_("missing closing '\"'")); + if (c == '"') + { + char *ilp_save = input_line_pointer; + + SKIP_WHITESPACE (); + if (*input_line_pointer == '"') + { + ++input_line_pointer; + continue; + } + input_line_pointer = ilp_save; + break; + } + + if (c == '\\') + switch (*input_line_pointer) + { + case '"': + case '\\': + c = *input_line_pointer++; + break; + + default: + if (c != 0) + as_warn (_("'\\%c' in quoted symbol name; " + "behavior may change in the future"), + *input_line_pointer); + break; + } + + *dst++ = c; + } + *dst = 0; } *--input_line_pointer = 0; return c; |