** Description changed:
I've found a regression in qemu-user-static. I'm using binfmt to run
riscv64 application on an x86-64.
Steps to reproduce (using golang for ease of cross-compiling):
--
$ cat rv.go
package main
import (
- "fmt"
- "os"
+ "fmt"
+ "os"
)
func main() {
- fmt.Println("Args are");
- for i, a := range os.Args {
- fmt.Println(i, a);
- }
+ fmt.Println("Args are");
+ for i, a := range os.Args {
+ fmt.Println(i, a);
+ }
}
$ go build ./rv.go
$ ./rv one two three
Args are
0 ./rv
1 one
2 two
3 three
$ export GOARCH=riscv64
$ go build ./rv.go
$ file ./rv
./rv: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV),
statically linked, Go
BuildID=9kA-_aeKgZkwtyYVUb7o/F43JNW5XxPX9ScBQrfs8/l6EzXXq8x8pfor-ByIh4/_zELq4T9-VKcpBXoempb,
not stripped
$ ./rv
Args are
0 ./rv
$ ./rv one
Args are
0 ./rv
$ ./rv one two three four
Args are
0 ./rv
1 two
2 three
3 four
$
--
As you can see, in the last run, the "one" argument is skipped.
There is a debian patch, linux-user-binfmt-P.diff (found in
qemu_6.0+dfsg-2expubuntu1.debian.tar.xz), that I think is the issue.
When we execute the binfmt-interpreter directly:
$ /usr/libexec/qemu-binfmt/riscv64-binfmt-P /path/to/rv /path/to/rv one two
Args are
0 /path/to/rv
1 one
2 two
Things work, however via the kernels binfmt-misc:
$ /path/to/rv one two
Args are
0 /path/to/rv
1 two
It doesn't.
-
- $ cat /proc/sys/fs/binfmt_misc/qemu-riscv64
+
+ $ cat /proc/sys/fs/binfmt_misc/qemu-riscv64
enabled
interpreter /usr/libexec/qemu-binfmt/riscv64-binfmt-P
flags: POCF
offset 0
magic 7f454c460201010000000000000000000200f300
mask ffffffffffffff00fffffffffffffffffeffffff
Note that the 'P' flag is set.
From the qemu code (linux-user/main.c):
- /*
- * get binfmt_misc flags
- */
- preserve_argv0 = !!(qemu_getauxval(AT_FLAGS) & AT_FLAGS_PRESERVE_ARGV0);
+ /*
+ * get binfmt_misc flags
+ */
+ preserve_argv0 = !!(qemu_getauxval(AT_FLAGS) & AT_FLAGS_PRESERVE_ARGV0);
- /*
- * Manage binfmt-misc preserve-arg[0] flag
- * argv[optind] full path to the binary
- * argv[optind + 1] original argv[0]
- */
- if (optind + 1 < argc && preserve_argv0) {
- optind++;
- }
+ /*
+ * Manage binfmt-misc preserve-arg[0] flag
+ * argv[optind] full path to the binary
+ * argv[optind + 1] original argv[0]
+ */
+ if (optind + 1 < argc && preserve_argv0) {
+ optind++;
+ }
Here, having P enabled will skip the argument.
I believe the debian patch needs to be reworked
(https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04639.html).
+
+ This breaks the ability to run debootstrap/mmdebstap for foreign archs.
ProblemType: Bug
DistroRelease: Ubuntu 21.10
Package: qemu-user-static 1:6.0+dfsg-2expubuntu1
ProcVersionSignature: Ubuntu 5.13.0-20.20-generic 5.13.14
Uname: Linux 5.13.0-20-generic x86_64
ApportVersion: 2.20.11-0ubuntu71
Architecture: amd64
CasperMD5CheckResult: pass
CurrentDesktop: ubuntu:GNOME
Date: Mon Oct 25 17:02:34 2021
InstallationDate: Installed on 2021-05-28 (149 days ago)
InstallationMedia: Ubuntu 21.04 "Hirsute Hippo" - Release amd64 (20210420)
KvmCmdLine: COMMAND STAT EUID RUID PID PPID %CPU COMMAND
MachineType: LENOVO 20W0CTO1WW
ProcKernelCmdLine: BOOT_IMAGE=/vmlinuz-5.13.0-20-generic
root=/dev/mapper/vgubuntu-root ro quiet splash vt.handoff=7
SourcePackage: qemu
UpgradeStatus: Upgraded to impish on 2021-10-21 (4 days ago)
dmi.bios.date: 09/07/2021
dmi.bios.release: 1.43
dmi.bios.vendor: LENOVO
dmi.bios.version: N34ET43W (1.43 )
dmi.board.asset.tag: Not Available
dmi.board.name: 20W0CTO1WW
dmi.board.vendor: LENOVO
dmi.board.version: Not Defined
dmi.chassis.asset.tag: No Asset Information
dmi.chassis.type: 10
dmi.chassis.vendor: LENOVO
dmi.chassis.version: None
dmi.ec.firmware.release: 1.8
dmi.modalias:
dmi:bvnLENOVO:bvrN34ET43W(1.43):bd09/07/2021:br1.43:efr1.8:svnLENOVO:pn20W0CTO1WW:pvrThinkPadT14Gen2i:skuLENOVO_MT_20W0_BU_Think_FM_ThinkPadT14Gen2i:rvnLENOVO:rn20W0CTO1WW:rvrNotDefined:cvnLENOVO:ct10:cvrNone:
dmi.product.family: ThinkPad T14 Gen 2i
dmi.product.name: 20W0CTO1WW
dmi.product.sku: LENOVO_MT_20W0_BU_Think_FM_ThinkPad T14 Gen 2i
dmi.product.version: ThinkPad T14 Gen 2i
dmi.sys.vendor: LENOVO
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1948684
Title:
qemu-user-static/binfmt skips first argument
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1948684/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs