JustasMasiulis / inline_syscall

Inline syscalls made easy for windows on clang
Apache License 2.0
638 stars 87 forks source link

error : invalid operand for instruction #3

Closed lIIIIIIIIl closed 3 years ago

lIIIIIIIIl commented 3 years ago
int main()
{
    std::uint64_t largeImmidiateValue{ 0x1234567812345678 };
    jm::detail::syscall(0, 0, 0, 0, 0, largeImmidiateValue);//error : invalid operand for instruction
}

I believe it has something to do with the input constraint "rn", because if I change it to "r", then it compiles.

JustasMasiulis commented 3 years ago

Looking into this.

I think I had similar issue earlier and may have fixed it in some other project of mine already.

lIIIIIIIIl commented 3 years ago

Changing it into "re" or "rZ" or "reZ" works for me so far.

https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html

asdf

JustasMasiulis commented 3 years ago

So I looked into this and it seems to compile just fine on godbolt with clang and gcc, but it does seem to be broken on clang-cl on my machine. I'd say this is probably a compiler bug.

Furthermore the e and Z constraints don't really make sense since your value is not something that fits into 32 bits and is being sign extended, however it still generates correct assembly so :shrug:

I tested just replacing "rn" with "reZ" on my private projects (with clang-cl that is broken in this case) and it seemed to not change codegen in any way on a release build.

Will probably make the change, although I'm a bit afraid I might break it on actual clang/gcc.

lIIIIIIIIl commented 3 years ago

Sorry I don't really understand how constraints works. I was typing random letters into the constraints string. "re" and "rZ" and "reZ" are the only ones I found that works so far for this instruction movq %[x], 48(%%rsp) https://godbolt.org/z/6jbrWW

Do you happen to know any good tutorial on how to write gcc extended asm, or assembly in general?

JustasMasiulis commented 3 years ago

Should be fixed.

Concerning the learning part I learned assembly mostly trough experience reading about instructions when debugging with tools like x64dbg and for extended asm the GCC docs for it are pretty good

lIIIIIIIIl commented 3 years ago

I think it needs to be "re", not "reZ". https://godbolt.org/z/6cfYnc

JustasMasiulis commented 3 years ago

Changed it