Skip to content

jit: Fail to run recursive programs #394

@vacantron

Description

@vacantron

Consider the following code to calculate fibonacci sequences:

long fib(int n)
{
    if (n == 0 || n == 1) {
        return n;
    }
    return fib(n - 1) + fib(n - 2);
}

int main()
{
    return fib(30);
}

and build it with the linker script and commands:

OUTPUT_ARCH("riscv")
ENTRY(main)

SECTIONS
{
    . = 0x10000;
}
$ make clean ENABLE_JIT=1 all
$ riscv32-unknown-elf-gcc -S -O2 -o fib.s fib.c
$ riscv32-unknown-elf-gcc -c -o fib.o fib.s
$ riscv32-unknown-elf-ld -T script.ld -o fib fib.o
$ build/rv32emu fib

It will fall into the infinite loop when executed by the rv32emu.

The problem only happens when the -O2 option enabled.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions