Usage of ptr causes illegal instruction

8 views
Skip to first unread message

Ryan Gonzalez

unread,
Sep 21, 2014, 7:05:26 PM9/21/14
to asmji...@googlegroups.com
Note: I'm posting this here instead of the issue tracker because I'm not sure whether or not this is a bug.

Here is the simplest code I can get that causes the error:

#include <asmjit/asmjit.h>
#include <iostream>

using namespace asmjit;
using namespace asmjit::host;

int main()
{
    int n;
    JitRuntime r;
    FileLogger logger{stdout};
    X86Compiler c{&r};
    c.setLogger(&logger);
    c.addFunc(kFuncConvHost, FuncBuilder1<void, void*>());
    X86GpVar p{c, kVarTypeIntPtr, "p"};
    c.setArg(0, p);
    c.mov(ptr(p), 1);
    c.endFunc();
    asmjit_cast<void(*)(int*)>(c.make())(&n);
    std::cout << n << std::endl;
    return 0;
}

Output:

L0:
*** ERROR: Illegal instruction (9).
mov [rdi], 1                        ; mov [p], 1 R
L1:
ret                                 ;             
Segmentation fault (core dumped)

What am I doing wrong?

--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated."
Personal reality distortion fields are immune to contradictory evidence. - srean
Check out my website: http://kirbyfan64.github.io/

Petr Kobalíček

unread,
Sep 21, 2014, 7:27:21 PM9/21/14
to asmjit-dev

Hi Ryan

In case that there is no register used the memory pointer size can't be determined automatically.

Use c.mov(dword_ptr(p), 1);

I should probably add a new error for this as it happens often.

Cheers,
Petr

--

---
You received this message because you are subscribed to the Google Groups "asmjit-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asmjit-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Gonzalez

unread,
Sep 21, 2014, 7:28:50 PM9/21/14
to asmji...@googlegroups.com
Thank you! That is probably a common error that has already bitten my twice.
Reply all
Reply to author
Forward
0 new messages