Skip to content

Commit

Permalink
x86: don't recognize quoted symbol names as registers or operators
Browse files Browse the repository at this point in the history
The concept of quoted symbols names was introduced pretty late. Utilize
it to allow access to symbols with names matching that of a register (or,
in Intel syntax, also an identifier-like operator).

This is primarily to aid gcc when generating Intel syntax output; see
their bug target/53929.
  • Loading branch information
jbeulich authored and ouuleilei-bot committed May 5, 2023
1 parent 324998b commit f2352e2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gas/config/tc-i386-intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ operatorT i386_operator (const char *name, unsigned int operands, char *pc)
return O_illegal;
}

/* See the quotation related comment in i386_parse_name(). */
if (*pc == '"')
return O_absent;

for (j = 0; i386_operators[j].name; ++j)
if (strcasecmp (i386_operators[j].name, name) == 0)
{
Expand Down
7 changes: 7 additions & 0 deletions gas/config/tc-i386.c
Original file line number Diff line number Diff line change
Expand Up @@ -12987,6 +12987,13 @@ i386_parse_name (char *name, expressionS *e, char *nextcharP)
const reg_entry *r = NULL;
char *end = input_line_pointer;

/* We only know the terminating character here. It being double quote could
be the closing one of a quoted symbol name, or an opening one from a
following string (or another quoted symbol name). Since the latter can't
be valid syntax for anything, bailing in either case is good enough. */
if (*nextcharP == '"')
return 0;

*end = *nextcharP;
if (*name == REGISTER_PREFIX || allow_naked_reg)
r = parse_real_register (name, &input_line_pointer);
Expand Down
1 change: 1 addition & 0 deletions gas/testsuite/gas/i386/i386.exp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ if [gas_32_check] then {
run_list_test "equ-bad"
run_dump_test "divide"
run_dump_test "quoted"
run_dump_test "quoted2"
run_dump_test "unary"
run_dump_test "padlock"
run_dump_test "crx"
Expand Down
7 changes: 7 additions & 0 deletions gas/testsuite/gas/i386/quoted.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ Disassembly of section .text:
[ ]*[a-f0-9]+:[ ]*ff 15 00 00 00 00[ ]+call \*0x0 [a-f0-9]+: (R_386_|dir)?32 x\(y\)
[ ]*[a-f0-9]+:[ ]*26 ff 15 00 00 00 00[ ]+call \*%es:0x0 [a-f0-9]+: (R_386_|dir)?32 x\(y\)
[ ]*[a-f0-9]+:[ ]*26 ff 15 00 00 00 00[ ]+call \*%es:0x0 [a-f0-9]+: (R_386_|dir)?32 x\(y\)
[ ]*[a-f0-9]+:[ ]*b8 00 00 00 00[ ]+mov \$0x0,%eax [a-f0-9]+: (R_386_|dir)?32 %eax
[ ]*[a-f0-9]+:[ ]*a1 00 00 00 00[ ]+mov 0x0,%eax [a-f0-9]+: (R_386_|dir)?32 %eax
[ ]*[a-f0-9]+:[ ]*a1 00 00 00 00[ ]+mov 0x0,%eax [a-f0-9]+: (R_386_|dir)?32 ecx
[ ]*[a-f0-9]+:[ ]*a1 00 00 00 00[ ]+mov 0x0,%eax [a-f0-9]+: (R_386_|dir)?32 xmm0
[ ]*[a-f0-9]+:[ ]*a1 00 00 00 00[ ]+mov 0x0,%eax [a-f0-9]+: (R_386_|dir)?32 not
[ ]*[a-f0-9]+:[ ]*a1 00 00 00 00[ ]+mov 0x0,%eax [a-f0-9]+: (R_386_|dir)?32 and
[ ]*[a-f0-9]+:[ ]*b8 00 00 00 00[ ]+mov \$0x0,%eax [a-f0-9]+: (R_386_|dir)?32 edx
#pass
10 changes: 10 additions & 0 deletions gas/testsuite/gas/i386/quoted.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ quoted:
call *"x(y)"
call *%es:"x(y)"
call %es:*"x(y)"

mov $"%eax", %eax
mov "%eax", %eax

.intel_syntax noprefix
mov eax, "ecx"
mov eax, "xmm0"
mov eax, "not"
mov eax, "and"
mov eax, offset "edx"
15 changes: 15 additions & 0 deletions gas/testsuite/gas/i386/quoted2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#objdump: -r
#name: i386 quoted symbols (data)
# Mach-O relocations appear in inverse order
#notarget: *-*-darwin

.*: +file format .*

RELOCATION RECORDS FOR \[\.data\]:
OFFSET +TYPE +VALUE
0+00 (R_386_|dir)?32 +%ebx
0+04 (R_386_|dir)?32 +%rdx
0+08 (R_386_|dir)?32 +eax
0+0c (R_386_|dir)?32 +cr0
0+10 (R_386_|dir)?32 +k0
#pass
9 changes: 9 additions & 0 deletions gas/testsuite/gas/i386/quoted2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.data
quoted:
.long "%ebx"
.long "%rdx"

.intel_syntax noprefix
.long "eax"
.long "cr0"
.long "k0"

0 comments on commit f2352e2

Please sign in to comment.