<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/147587>147587</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            LLVM 21 X86 backend produces invalid asm syntax for $ dollar symbol names
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jeffreysandoval
      </td>
    </tr>
</table>

<pre>
    Starting in LLVM 21 the following test case produces invalid x86-64 assembly output:

```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 
target triple = "x86_64-unknown-linux-gnu" 
 
@"$dollarsymbol" = external global [1 x i32] 
 
define i32 @foo() { 
  %r = load i32, ptr @"$dollarsymbol", align 4 
  ret i32 %r 

```

The llc output is as follows:

https://godbolt.org/z/3jnrcTeqW

```
$ llc -O0 --x86-asm-syntax=att bug.ll -o bug.s
```

```
foo: # @foo
        movq    $dollarsymbol@GOTPCREL(%rip), %rax
 movl    (%rax), %eax
        retq
```

This asm output is rejected by both the GNU assembler and LLVM:

https://godbolt.org/z/1cra7v3rd
```
$ /usr/bin/as -o bug.o bug.s
```

```
<source>: Assembler messages:
<source>: Warning: end of file not at end of a line; newline inserted
<source>:2: Error: junk `(%rip)' after expression
<source>:2: Error: junk `(%rip)' after expression
Compiler returned: 1
```

https://godbolt.org/z/xhbGjan45 
```
$ clang -o bug.o bug.s
```

```
<source>:2:39: error: unexpected token in argument list
 movq    $dollarsymbol@GOTPCREL(%rip), %rax
 ^
Compiler returned: 1
```

The issue does not occur when using the integrated assembler, e.g.:

```
$ llc -O0 --filetype=obj bug.ll -o bug.o # this is successful
```

We originally encountered the issue when emitting AT&T assembly syntax.  For Intel syntax, it appears that GNU binutils accepts the Intel asm output but LLVM still rejects it, e.g.:

https://godbolt.org/z/TK77d8MsK

```
$ llc -O0 --x86-asm-syntax=intel bug.ll -o bug.intel.s
```

```
foo: # @foo
        mov     rax, qword ptr [rip + $dollarsymbol@GOTPCREL]
        mov     eax, dword ptr [rax]
 ret
```

GNU binutils accepts the resulting Intel asm: https://godbolt.org/z/qKbEnPoYr
But LLVM rejects the resulting Intel asm: https://godbolt.org/z/681jWshGz

We are encountering this issue with our closed source Fortran front-end, which uses LLVM as a backend and produces many symbols beginning with `$` dollar symbols.  It appears that this commit caused the initial issue:

https://github.com/llvm/llvm-project/commit/3acccf042ab8a7b7e663bb2b2fac328d9bf65b38

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVltz2zYT_TXQyw41FHgR9aAH-SJPJsmXzBe3bp86ALmkYIMAjYst5dd3AEryRU6TNNVIIgACi91zdg_ArBWdQlyS4owUFxPm3Uab5S22rcGdZarRD0xOuG52yy-OGSdUB0LBhw-_fwQ6A7dBaLWU-jG8cGgd1MwiDEY3vkYLQj0wKRrYVmVS5sCsxZ7LHWjvBu9ItiJp_Jbp_puuHDMdOmiYY5LttHdAsgsglGLSk2yFyUDnKclWGY1_oTt72Q2tMo9_iTg2ZrQi2WpGq6St0n1LxaHysLzMky9hGqXw5IgzYpB4cGJblX-VeeLVndKPKpFC-W3SKb9fE34kTwmlhOaNlpIZu-u5lvF9dgG4dWgUk9BJzZkEUpzNYAsio6S4OFhosBUKwyCQPG21JsGpBZD5WZwChBYmmpOaNXExPYfBGfjW3uE9k6JTkI8WDLrRfrSUrsg87v6cCJKurjcIUtZ7ukBYYHZPuD2St3FuiD26JnTd6YZr6abadISuvxK6zm6Vqa_x_uaUa0LzaD_5lEKShCRhtk_sTjm2JdkFcw6476ZSQqJjy576-LwboMpWQGh2AC7EOn56_XAfnq_BydOrT9efz_9_-SGiXBgxELoIgIUO2wYTvX6Q49pqP3icgeOM_cegu38Lxohc_wxHg7dYO2yA74Brt4mldPW_3w4lggaYamKh_TDQs9qw-UNmmjdQJnTtrSF0zYUidM3sAdEfwpV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