Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang as an x64 assembler - Masm x64 #99

Open
UnlimitedChild opened this issue Jan 19, 2020 · 12 comments
Open

Clang as an x64 assembler - Masm x64 #99

UnlimitedChild opened this issue Jan 19, 2020 · 12 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@UnlimitedChild
Copy link

UnlimitedChild commented Jan 19, 2020

Hello,

why Clang does not support the basic directive - "offset". This topic has been discussed many times
https://lists.llvm.org/pipermail/llvm-bugs/2017-April/054674.html
https://reviews.llvm.org/D37461
https://stackoverflow.com/questions/43223287/why-does-this-simple-assembly-program-work-in-att-syntax-but-not-intel-syntax
https://bugs.llvm.org/show_bug.cgi?id=22511

In general, Сlang does not support many assembler properties, for example, the ability to represent numbers is limited. Should we expect more complete support for assembler dialects in the future?

We can’t live without the offset directive ..

// 
// RUN: clang -mllvm --x86-asm-syntax=intel -c hello.asm
// RUN: clang hello.o -o hello.exe

//.intel_syntax
.intel_syntax noprefix

.data
#define Data_ADDR offset .ascii
Key:
    .ascii "Hello, world!\n"
    .set mylen, .-Key

.text
.global start
foo:
mov r15 , 555  
MOV r14 , 555
MOV r13 , 555  
MOV r12 , 555 
MOV r11 , 555 
MOV r10 , 555 
MOV r9 , 555 
MOV r8 , 555 
MOV rbp , 555  
MOV rax , 555 
MOV rdi , 555 
MOV rsi , 555  
MOV rdx , 555 
MOV rcx , 6555  
MOV rbx , 555  
MOV rax , 555  
nop
nop
nop
MOV rax , foo
MOV rax , [foo]
lea rax , foo
lea rax , [foo]
nop
MOV rax , .ascii
MOV rax , [.ascii]
lea rax , .ascii
lea rax , [.ascii]
nop
MOV rax , offset Key
mov rax , Data_ADDR

// MOV rax , offset foo
// MOV rax , offset [foo]
// lea rax , offset foo
// lea rax , offset [foo]
// MOV rax , addr foo
// MOV rax , addr [foo]
// lea rax , addr foo
// lea rax , addr [foo]

Thanks for the work!

@JonChesterfield
Copy link
Collaborator

Last time I looked there was a different feature set working for at&t, so there's an outside chance that changing dialect would be a workaround.

@ericastor
Copy link
Contributor

ericastor commented Jan 19, 2020 via email

@ericastor
Copy link
Contributor

ericastor commented Jan 19, 2020 via email

@UnlimitedChild
Copy link
Author

ericastor Thank you very much for the detailed information!

Some functions that worked before do not work today.
echo "mov eax, eax" | llvm-mc -x86-asm-syntax=intel

`C:\msys64\mingw64\bin>echo "mov eax, eax" | llvm-mc -x86-asm-syntax=intel
.text
:1:1: error: invalid instruction mnemonic 'mov eax, eax'
"mov eax, eax"
^~~~~~~~~~~~

C:\msys64\mingw64\bin>`

@ericastor
Copy link
Contributor

@UnlimitedChild I can't replicate your "mov eax, eax" problem locally on my Linux machine, at least. Can you confirm what version of llvm-mc you're using? Running llvm-mc --version should give all the information we need.

@ericastor
Copy link
Contributor

Oh, and please note that clang does not currently compile MASM-syntax assembly directives, etc. - it mostly accepts Intel syntax (omitted size suffixes, dst, src operand ordering), but work is still being done as more bugs are found. As mentioned, AT&T syntax is better-supported at the moment.

I'm working on a MASM-compatible LLVM-based assembler (llvm-ml) in my spare time, but am not sure how long that will take. (llvm-dev posts so far: RFC, and a few other threads)

@UnlimitedChild
Copy link
Author

@UnlimitedChild I can't replicate your "mov eax, eax" problem locally on my Linux machine, at least. Can you confirm what version of llvm-mc you're using? Running llvm-mc --version should give all the information we need.

C:\msys64\mingw64\bin>llvm-mc -version
LLVM (http://llvm.org/):
LLVM version 9.0.0
Optimized build.
Default target: x86_64-w64-windows-gnu

@UnlimitedChild
Copy link
Author

Oh, and please note that clang does not currently compile MASM-syntax assembly directives, etc. - it mostly accepts Intel syntax (omitted size suffixes, dst, src operand ordering), but work is still being done as more bugs are found. As mentioned, AT&T syntax is better-supported at the moment.

Thank you, everything is clear =)

I'm working on a MASM-compatible LLVM-based assembler (llvm-ml) in my spare time, but am not sure how long that will take. (llvm-dev posts so far: RFC, and a few other threads)

Great news, I think that there will be no problems with testing. A sufficient number of people are interested in this opportunity. I already found a development branch for macro assembler
https://github.com/llvm/llvm-project/blob/master/llvm/tools/llvm-ml/llvm-ml.cpp

It's hard to say where the syntax integration should go, there is a very good project that implements support for macro assembler (x32-x64) - https://github.com/Terraspace/UASM, In the project you can see the entire implementation of macro assembler, see the internal logic ... in addition, some documents will be useful and informative -
Microsoft Corporation - Microsoft Macro Assembler 6.11 Reference Manual_Environment and Tools (1992, Microsoft Corporation).pdf
Microsoft Corporation - Microsoft Macro Assembler 6.11 Reference Manual_Getting Started (1992, Microsoft Corporation).pdf
Microsoft Corporation - Microsoft Macro Assembler 6.11 Reference Manual_Macro Assembler Reference (1992, Microsoft Corporation).pdf
Microsoft Corporation - Microsoft Macro Assembler 6.11 Reference Manual_Programmers Guide (1992, Microsoft Corporation).pdf

This is the most comprehensive macro assembler documentation. The rest of the description can be found here - https://docs.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=vs-2017

Is there some kind of UML diagram to describe the expected llvm-ml assembly process?

@ericastor
Copy link
Contributor

@UnlimitedChild That's the documentation I'm referencing, and the "llvm-ml.cpp" you found is in fact the development placeholder I'm working on. I'd certainly like not to be the only one working on it! I'm currently working to land the first commit of substance, though that may take a bit due to it not being my 100% focus while at work.

Please note that UASM (and every other open-source MASM project I've found) is released under a license that is generally considered incompatible with LLVM's license, so we cannot reference their code while building this.

As for a UML diagram - I'm not sure what you mean. At early stages of this project, we will be testing MASM support by building it through llvm-ml. At later stages (once it's proven to mostly work), it should be possible for clang-cl to build MASM files directly (just as with .s files on other platforms), by defaulting to MASM support when compiling files with the extension ".asm".

@UnlimitedChild
Copy link
Author

UnlimitedChild commented Jan 21, 2020

A few questions:
2. Is there anyone around who would be willing to answer questions
regarding the intended architecture of llvm-mc and the AsmParser classes?
I'd like to make sure my proposals fit well into the design... and I'm
starting to have trouble finding where these extensions should go. (Also,
I've had some trouble getting used to the recursive-descent parser
conventions being used. For example, how should one handle "try parsing
this identifier as a register, and if that fails, check if it's defined as
a symbol" while not emitting Errors from the first attempt?)

This is what I had in mind, which means it is still under discussion.

Please note that UASM (and every other open-source MASM project I've found) is released under a license that is generally considered incompatible with LLVM's license, so we cannot reference their code while building this.

Indeed, did not think about it.

@UnlimitedChild
Copy link
Author

C++ is actually a macro language with inline functions, so macro assembler should use similar processing logic, where the architectural implementation may be similar. Instead of C++ templates, macro operations will be processed.

@RKSimon RKSimon added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Apr 12, 2022
@llvmbot
Copy link
Member

llvmbot commented Apr 12, 2022

@llvm/issue-subscribers-clang-frontend

searlmc1 referenced this issue in ROCm/llvm-project Nov 27, 2023
…inline/db2da08

Promote develop branch (as of db2da08) to mainline
ergawy added a commit to ergawy/llvm-project that referenced this issue Jun 7, 2024
Adds a TODO for the duplicated utils that we had to copy for do
concurrent mapping. Also introduces the duplicate utils in a separate
`internal` namespace to avoid naming conflicts.
RevySR pushed a commit to revyos/llvm-project that referenced this issue Jul 27, 2024
… unnecessary vtype-preserving sequences (llvm#99)

* [LLVM][XTHeadVector] Initial `RedundantVSETVLIElimination` pass

* [LLVM][XTHeadVector] `RedundantVSETVLIElimination`

This pass removes code sequences like:

```
csrr <r1>, vl
csrr <r2>, vtype
<a lot of th.vsetvl/th.vsetvli>
th.vsetvl zero, <r1>, <r2>
```

* [LLVM][XTHeadVector] Update tests

* [LLVM][XTHeadVector] Update tests

* [LLVM][XTHeadVector] Fix comments

* [LLVM][XTHeadVector] Fix comments

* [LLVM][XTHeadVector] More comments

* [LLVM][XTHeadVector] Update tests

* [LLVM][XTHeadVector] add option `riscv-enable-vsetvli-elim`
teresajohnson added a commit that referenced this issue Aug 12, 2024
alexanderguy pushed a commit to alexanderguy/llvm-project that referenced this issue Sep 25, 2024
changkhothuychung pushed a commit to changkhothuychung/llvm-project that referenced this issue Oct 13, 2024
Otherwise documentation generation fails due to missing any spellings:
~/dev/llvm/clang/docs/../include/clang/Basic/Attr.td:962:5: error: Attribute has no supported spellings; cannot be documented
def CXX26Annotation : InheritableParamAttr {
    ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

5 participants