westerndigitalcorporation / swerv-ISS

Western Digital’s Open Source RISC-V SweRV Instruction Set Simulator
201 stars 41 forks source link

C++ Program either gets caught in infinite loop or get aborted! #21

Closed anubane closed 3 years ago

anubane commented 3 years ago

I have a multi-file (3 .cpp files and 2 .h files) C++ code that uses new, new[], delete, and delete[] operators to allocate large chunks of memory and performs some floating point operations (requires division by sqrt()). The program compiles and runs well with regular g++ and produces the required output. I now want to convert it to RISC-V instructions.

  1. I first used the GNU RISC-V compiler toolchain to compile the program with following command: riscv32-unknown-elf-g++ -w -march=rv32imafc -mabi=ilp32f -DPREALLOCATE=1 -mcmodel=medany -fno-common -static -Iinclude/ f1.cpp f2.cpp f3.cpp -o executable here executable is the compiled binary file.

  2. Since no errors are thrown at compile time, I proceeded to run the whisper simulator as follows: whisper --isa imafc --target executable --logfile mylog --profileinst prfl where mylog and prfl are output file paths.

  3. The log file generated exceeds 6 GB in size and it doesn't terminate, so I assume that it is stuck in some infinite loop.

  4. I tried adding the _start() function and tohost variable which didn't work either (same problem as 3 above).

  5. I generated an object dump for executable and captured the (hex) addresses of starting address of main(), its ending address and address of tohost and passed them as parameters to --startpc, --endpc and --tohost respectively, in which case, the program was aborted after 64 illegal operations and ~300 MB of log file.

I think I am making some mistake. Kindly help me fix this issue or share the correct steps to generate the RISC-V assembly instructions for my C++ program.

anubane commented 3 years ago

This issue was reposted in the latest repo, since this repo is no longer supported.