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

    <tr>
        <th>Summary</th>
        <td>
            llvm-ml cannot assemble LLVM's own MASM-syntax source code
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          statham-arm
      </td>
    </tr>
</table>

<pre>
    The LLVM project contains `llvm-ml`, a MASM-syntax assembler intended to behave like `ml.exe` or `ml64.exe`. As of https://reviews.llvm.org/D121510, it also contains some MASM-syntax assembly source files in `llvm/lib/Support/BLAKE3`. But the former cannot accept the latter as input:
```
$ build/bin/llvm-ml -m64 llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:8:27: error: unexpected token in align directive
_TEXT   SEGMENT ALIGN(16) 'CODE'
                          ^
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:2408:25: error: endp outside of procedure block
blake3_hash_many_avx512 ENDP
                        ^
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:2490:1: error: symbol '@@' is already defined
@@:
^
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:2502:33: error: endp outside of procedure block
blake3_compress_in_place_avx512 ENDP
                                ^
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:2534:1: error: symbol '@@' is already defined
@@:
^
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:2585:1: error: symbol '@@' is already defined
@@:
^
llvm/lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm:2601:28: error: endp outside of procedure block
blake3_compress_xof_avx512 ENDP
                           ^
```
My own partial diagnosis of the problems, just from looking at the source file:

It looks as if declaring `@@` as a label multiple times is expected to be allowed, with `jmp @b` or `jmp @f` going to the previous or next instance of it respectively. But `llvm-ml` is expecting it to be like any other label, defined at most once.

The 'endp outside of procedure block' errors appear to be arising from nesting of two `PROC`/`ENDP` pairs around the same code in order to define two procedures with the same address and extent (`foo PROC`, `bar PROC`, code code code, `bar ENDP`, `foo ENDP`). `llvm-ml` is complaining on the second `ENDP`, suggesting that the real `ml64.exe` is able to track multiple open `PROC` definitions and `llvm-ml` isn't.

As for the first error in the segment directive: it _looks_ to me as if `llvm-ml` has terminated parsing after the word `SEGMENT`, and attempted to parse the rest of the line independently, as if there had been a newline in between. (For example, I can write `_TEXT SEGMENT mov rax,1` without provoking an error.) So the suffix `ALIGN(16)` is being regarded as a standalone alignment directive, rather than an attribute on the segment directive, and that's why the error message about `'CODE'` is reporting an unexpected token in the _align_ directive and not in the _segment_ directive.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV9tu2zgQ_Rr7hYghS74--MFJnKLYpC02QbFvBiXRNhuKFEjKl7_fM6R8y7bdWws0cGSZIjlnzhzOjHJTHmYvG8EeHz8_sdqaL6LwrDDac6kd64wSpbbVTaVw10nvGGdP8-enG3fAhD3jzokqV8Iyqb3QpSiZNywXG74VTMlXQRtUqif2AjfM2Ph7NGhHemzumFmxjfe162TzTvqAjxVbKXauR5Z7xq4xdN9P-8N-QCA948qZM0ZnKvE1VAc8aWwh2Eoq4YDw6A32UzLH9bmpa2M97m4f578tsoDotvHMg5CVsRUcK7jWBiaLQtTxgeLe4wGnLevGE-zkvpPMiaH4iT_TAcsbqUpsn0tNRiOT7KYaDdj3gWCJ4q8iW_LtfthPl_vJ6GY0WO6kLs3OLSu3LXrcVdHSj9kqm0_wn45xYcJaY-mm0WJfQxEhsK9CE4tcybVmpbQYl1sRMSxfFn-8MMaeF--eFh9e2Pzx_bsPnXTSH3XSKeuk47uP9wt8xdnsm3-d4eLHOpUOkuDX8MovaLVmpvFOloIECOEXomysYLkyxWuE0JrYcLdZVlwf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