I'm trying to set up a testing environment for my project using semihosting within QEMU.
So far I had no issues with hello.c
following this answer, however I'm having trouble getting it to work with CMake.
Here's how I'm building the exact same hello.c
(toolchain file on pastebin):
C:\hello_cmake>cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake . -Btmp
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- Configuring done
-- Generating done
-- Build files have been written to: C:/hello_cmake/tmp
C:\hello_cmake>cmake --build tmp --verbose
"C:/Program Files/CMake/bin/cmake.exe" -SC:/hello_cmake -BC:/hello_cmake/tmp --check-build-system CMakeFiles/Makefile.cmake 0
"C:/Program Files/CMake/bin/cmake.exe" -E cmake_progress_start C:/hello_cmake/tmp/CMakeFiles C:/hello_cmake/tmp//CMakeFiles/progress.marks
C:/buildtools/bin/make.exe -f CMakeFiles/Makefile2 all
make.exe[1]: Entering directory 'C:/hello_cmake/tmp'
C:/buildtools/bin/make.exe -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/depend
make.exe[2]: Entering directory 'C:/hello_cmake/tmp'
"C:/Program Files/CMake/bin/cmake.exe" -E cmake_depends "Unix Makefiles" C:/hello_cmake C:/hello_cmake C:/hello_cmake/tmp C:/hello_cmake/tmp C:/hello_cmake/tmp/CMakeFiles/hello.dir/DependInfo.cmake --color=
make.exe[2]: Leaving directory 'C:/hello_cmake/tmp'
C:/buildtools/bin/make.exe -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/build
make.exe[2]: Entering directory 'C:/hello_cmake/tmp'
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
"C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe" -specs=rdimon.specs -mcpu=cortex-a9 -O0 -g -MD -MT CMakeFiles/hello.dir/hello.c.obj -MF CMakeFiles/hello.dir/hello.c.obj.d -o CMakeFiles/hello.dir/hello.c.obj -c C:/hello_cmake/hello.c
[100%] Linking C executable hello
"C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe" -lc -lrdimon -lc -lrdimon "CMakeFiles/hello.dir/hello.c.obj" -o hello
make.exe[2]: Leaving directory 'C:/hello_cmake/tmp'
[100%] Built target hello
make.exe[1]: Leaving directory 'C:/hello_cmake/tmp'
"C:/Program Files/CMake/bin/cmake.exe" -E cmake_progress_start C:/hello_cmake/tmp/CMakeFiles 0
And here's how I invoke QEMU:
qemu-system-arm.exe -nographic -machine xilinx-zynq-a9 -cpu cortex-a9 -monitor none -serial stdio -kernel app -m 512 -semihosting
QEMU almost immediately exits without producing any output, however -d exec
and -d init
logs look like code is running and semihosting actually works:
...
Trace 0: 0000000004705540 [00000400/0000828c/000005a0/ff000000] __libc_init_array
Trace 0: 0000000004705780 [00000400/000081ec/000005a0/ff000000] frame_dummy
Trace 0: 00000000047058c0 [00000400/00010460/000005a0/ff000000] main
Trace 0: 0000000004705c00 [00000400/00029158/000005a0/ff000000] printf
Trace 0: 0000000004706040 [00000400/000301f0/000005a0/ff000000] _vfprintf_r
Trace 0: 0000000004706440 [00000400/000375b8/000005a0/ff000000] _localeconv_r
Trace 0: 00000000047065c0 [00000400/0003020c/000005a0/ff000000] _vfprintf_r
Trace 0: 00000000047067c0 [00000400/0000a704/000005a0/ff000000] strlen
...
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...handling as semihosting call 0xc
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...handling as semihosting call 0x13
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...handling as semihosting call 0x5
Taking exception 16 [Semihosting call] on CPU 0
...from EL1 to EL0
...
The question is: what does CMake do (or doesn't do) that breaks printf
output?
For the record:
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10)
QEMU emulator version 7.0.0 (v7.0.0-11902-g1d935f4a02-dirty)
Microsoft Windows [Version 10.0.19044.1645]
cmake version 3.22.2