Skip to content

Command line arguments are not passed correctly with user-space semihosting

Host environment

  • Operating system: Ubuntu 20.04 WSL2 on Windows 10 (also experienced on native Ubuntu 20.04 and containerised)
  • OS/kernel version: Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Architecture: x86_64
  • QEMU flavor: qemu-arm
  • QEMU version: qemu-arm version 6.1.90 (v6.2.0-rc0-10-gb30187ef)
  • QEMU command line:
    $ qemu-arm -cpu cortex-m7 ./a.out 123 test

Emulated/Virtualized environment

  • Using user-space emulation

Description of problem

The emulated process always receives a value of 1 for argc, with argv[0] returning seemingly random characters (in Ubuntu packaged qemu 5.2), but correlating with command-line input (output below from master built qemu 6.1):

$ qemu-arm -cpu cortex-m7 ./a.out 123 test
argc: 1
argv: 
 - @@@

$ qemu-arm -cpu cortex-m7 ./a.out 
argc: 1
argv:
 [0] @

Steps to reproduce

  1. Compile the following program with ARM embedded toolchain:
#include <iostream>

int main(int argc, char* argv[]) {
	std::cout << "argc: " << argc << "\n";
	std::cout << "argv: \n";

	for (int i = 0; i < argc; i++)
		std::cout << " [" << i << "] " << argv[i] << "\n";
	return 0;
}
$ $CXX --version
arm-none-eabi-g++ (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ $CXX main.cpp --specs=rdimon.specs -mcpu=cortex-m7
  1. Run in user-space (semihosted):
$ qemu-arm -cpu cortex-m7 ./a.out 
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information