[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue when using jit_label() before a jump or branch

From: Franz Flasch
Subject: Issue when using jit_label() before a jump or branch
Date: Sun, 23 Jan 2022 13:00:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0


I think there is kind of an issue in GNU lightning when using a label as jump target if this label was created immediately before a jump or branch. Here is an example:

    /* get a label here */
    label = jit_label();

    /* Prepare forward jump */
    jump = jit_jmpi();
    forward = jit_forward();
    jit_patch_at(jump, forward);

    /* Some random instructions */
    jit_addi(JIT_R0, JIT_R0, 42);
    /* Link forward jump */

    /* Some random instructions */
    jit_addi(JIT_R0, JIT_R0, 42);

    /* Now prepare backward jump to first label */
    jump2 = jit_jmpi();
    jit_patch_at(jump2, label);


The above instructions result into the following GNU lightning instructions:

    L0: %rax /* prolog */
        jmpi L2
    L4: %rax
        addi %rax %rax 0x2a
    L2: %rax
        addi %rax %rax 0x2a
        jmpi L2
    L5: %rax
        retr %rax
         \__ live %rax
         \__ ret
    L3: /* epilog */

As you can see the second jump is wrong. It jumps back to L2 even though it should jump to L0 (before the first jump). When I use the label from the first jump like this

    jit_patch_at(jump2, jump);

it works as expected.

But why can't I use a normal label here? Is this the intended behavior or is this a bug?

If there is another instruction between jit_label() and jit_jmpi() it also works as expected.

The same behavior also occurs with branches.

I could just use the first jump label to solve this issue, however my code generation engine currently does not know about this in advance so I rely on normal labels to work correctly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]