[PATCH for-7.0 v5] qemu-binfmt-conf.sh: mips: allow nonzero EI_ABIVERSION, distinguish o32 and n32
With the command line flag -mplt and a recent toolchain, ELF binaries generated by gcc can obtain EI_ABIVERSION=1, which makes, e.g., gcc three-stage bootstrap in a mips-unknown-linux-gnu qemu-user chroot fail since the binfmt-misc magic does not match anymore. Also other values are technically possible. qemu executes these binaries just fine, so relax the mask for the EI_ABIVERSION byte at offset 0x08. In addition, extend magic string to distinguish mips o32 and n32 ABI. This information is given by the EF_MIPS_ABI2 (0x20) bit in the e_flags field of the ELF header (a 4-byte value at offset 0x24 for the here applicable ELFCLASS32). See-also: ace3d65459 Signed-off-by: Andreas K. Hüttel Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: WANG Xuerui Cc: Laurent Vivier Cc: WANG Xuerui Cc: Richard Henderson Cc: Alex Bennee Cc: Philippe Mathieu-Daudé Closes: https://gitlab.com/qemu-project/qemu/-/issues/843 --- v5: Fully relax mask for EI_ABIVERSION for all of mips; squash patches since they touch the same lines v4: Unchanged repost of v3 v3: Add the magic extension to distinguish n32 and o32 v2: Add the same EI_ABIVERSION fix for little endian as for big endian v1: Initial version, only handling EI_ABIVERSION=1 on BE scripts/qemu-binfmt-conf.sh | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index e9bfeb94d3..9cb723f443 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -60,28 +60,28 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. -mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' mips_family=mips -mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' mipsel_family=mips -mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' +mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' mipsn32_family=mips -mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' +mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' mipsn32el_family=mips mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' mips64_family=mips mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' mips64el_family=mips sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00' -- 2.34.1
[PATCH v4 1/2] qemu-binfmt-conf.sh: allow elf EI_ABIVERSION=1 for mips
With the command line flag -mplt and a recent toolchain, ELF binaries generated by gcc can obtain EI_ABIVERSION=1, see below, which makes, e.g., gcc three-stage bootstrap in a mips-unknown-linux-gnu qemu-user chroot fail since the binfmt-misc magic does not match anymore. qemu executes these binaries just fine, so relax the mask slightly. CHOST=mips-unknown-linux-gnu (and also mipsel-unknown-linux-gnu) CFLAGS="-O2 -march=mips32 -mabi=32 -mplt -pipe" gcc-11.2, binutils-2.37, glibc-2.34 | /* | - * ELF dump of './prev-gcc/build/gengenrtl' | - * 29608 (0x73A8) bytes | + * ELF dump of './gcc/build/gengenrtl' | + * 54532 (0xD504) bytes | */ | | Elf32_Dyn dumpedelf_dyn_0[]; | struct { | Elf32_Ehdr ehdr; | Elf32_Phdr phdrs[12]; | - Elf32_Shdr shdrs[33]; | + Elf32_Shdr shdrs[44]; | Elf32_Dyn *dyns; | } dumpedelf_0 = { | | .ehdr = { | .e_ident = { /* (EI_NIDENT bytes) */ | /* [0] EI_MAG:*/ 0x7F,'E','L','F', | /* [4] EI_CLASS: */ 1 , /* (ELFCLASS32) */ | /* [5] EI_DATA: */ 2 , /* (ELFDATA2MSB) */ | /* [6] EI_VERSION:*/ 1 , /* (EV_CURRENT) */ | /* [7] EI_OSABI: */ 0 , /* (ELFOSABI_NONE) */ | - /* [8] EI_ABIVERSION: */ 0 , | + /* [8] EI_ABIVERSION: */ 1 , | /* [9-15] EI_PAD: */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | }, | .e_type = 2 , /* (ET_EXEC) */ | .e_machine = 8 , /* (EM_MIPS) */ | .e_version = 1 , /* (EV_CURRENT) */ | (...) Signed-off-by: Andreas K. Hüttel --- scripts/qemu-binfmt-conf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index e9bfeb94d3..fc2f856800 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -61,11 +61,11 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' mips_family=mips mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' mipsel_family=mips mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -- 2.34.1
[PATCH v4 2/2] qemu-binfmt-conf.sh: Extend magic to distinguish mips o32 and n32 ABI
This information is given by the EF_MIPS_ABI2 (0x20) bit in the e_flags field of the ELF header (a 4-byte value at offset 0x24 for the here applicable ELFCLASS32). See-also: https://www.mail-archive.com/qemu-devel@nongnu.org/msg732572.html Signed-off-by: Andreas K. Hüttel --- scripts/qemu-binfmt-conf.sh | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index fc2f856800..5f44346166 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -60,20 +60,20 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. -mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' mips_family=mips -mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' mipsel_family=mips -mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' +mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' mipsn32_family=mips -mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' +mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' mipsn32el_family=mips mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -- 2.34.1
qemu-binfmt-conf.sh: improvements for mips
Re-sending v3 unchanged as requested. The first patch has already been submitted earlier and is unchanged from v2. The second patch extends it and resolves issue 843, "duplicate magic mips patterns". Tested with various self-bootstrapped Gentoo chroots and in production on the Gentoo release engineering stage builder.
[PATCH v3 2/2] qemu-binfmt-conf.sh: Extend magic to distinguish mips o32 and n32 ABI
This information is given by the EF_MIPS_ABI2 (0x20) bit in the e_flags field of the ELF header (a 4-byte value at offset 0x24 for the here applicable ELFCLASS32). See-also: https://www.mail-archive.com/qemu-devel@nongnu.org/msg732572.html Signed-off-by: Andreas K. Hüttel --- scripts/qemu-binfmt-conf.sh | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index fc2f856800..5f44346166 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -60,20 +60,20 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. -mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' mips_family=mips -mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' mipsel_family=mips -mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' +mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' mipsn32_family=mips -mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' +mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' mipsn32el_family=mips mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -- 2.34.1
[PATCH v3 1/2] qemu-binfmt-conf.sh: allow elf EI_ABIVERSION=1 for mips
With the command line flag -mplt and a recent toolchain, ELF binaries generated by gcc can obtain EI_ABIVERSION=1, see below, which makes, e.g., gcc three-stage bootstrap in a mips-unknown-linux-gnu qemu-user chroot fail since the binfmt-misc magic does not match anymore. qemu executes these binaries just fine, so relax the mask slightly. CHOST=mips-unknown-linux-gnu (and also mipsel-unknown-linux-gnu) CFLAGS="-O2 -march=mips32 -mabi=32 -mplt -pipe" gcc-11.2, binutils-2.37, glibc-2.34 | /* | - * ELF dump of './prev-gcc/build/gengenrtl' | - * 29608 (0x73A8) bytes | + * ELF dump of './gcc/build/gengenrtl' | + * 54532 (0xD504) bytes | */ | | Elf32_Dyn dumpedelf_dyn_0[]; | struct { | Elf32_Ehdr ehdr; | Elf32_Phdr phdrs[12]; | - Elf32_Shdr shdrs[33]; | + Elf32_Shdr shdrs[44]; | Elf32_Dyn *dyns; | } dumpedelf_0 = { | | .ehdr = { | .e_ident = { /* (EI_NIDENT bytes) */ | /* [0] EI_MAG:*/ 0x7F,'E','L','F', | /* [4] EI_CLASS: */ 1 , /* (ELFCLASS32) */ | /* [5] EI_DATA: */ 2 , /* (ELFDATA2MSB) */ | /* [6] EI_VERSION:*/ 1 , /* (EV_CURRENT) */ | /* [7] EI_OSABI: */ 0 , /* (ELFOSABI_NONE) */ | - /* [8] EI_ABIVERSION: */ 0 , | + /* [8] EI_ABIVERSION: */ 1 , | /* [9-15] EI_PAD: */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | }, | .e_type = 2 , /* (ET_EXEC) */ | .e_machine = 8 , /* (EM_MIPS) */ | .e_version = 1 , /* (EV_CURRENT) */ | (...) Signed-off-by: Andreas K. Hüttel --- scripts/qemu-binfmt-conf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index e9bfeb94d3..fc2f856800 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -61,11 +61,11 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' mips_family=mips mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' mipsel_family=mips mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -- 2.34.1
qemu-binfmt-conf.sh: mips improvements
Two patches; the first one has been under review before, the second builds on it and extends the binfmt-misc magic to differentiate between o32 and n32 binaries (see also issue 843).
[PATCH v2] qemu-binfmt-conf.sh: allow elf EI_ABIVERSION=1 for mips
With the command line flag -mplt and a recent toolchain, ELF binaries generated by gcc can obtain EI_ABIVERSION=1, see below, which makes, e.g., gcc three-stage bootstrap in a mips-unknown-linux-gnu qemu-user chroot fail since the binfmt-misc magic does not match anymore. qemu executes these binaries just fine, so relax the mask slightly. CHOST=mips-unknown-linux-gnu (and also mipsel-unknown-linux-gnu) CFLAGS="-O2 -march=mips32 -mabi=32 -mplt -pipe" gcc-11.2, binutils-2.37, glibc-2.34 | /* | - * ELF dump of './prev-gcc/build/gengenrtl' | - * 29608 (0x73A8) bytes | + * ELF dump of './gcc/build/gengenrtl' | + * 54532 (0xD504) bytes | */ | | Elf32_Dyn dumpedelf_dyn_0[]; | struct { | Elf32_Ehdr ehdr; | Elf32_Phdr phdrs[12]; | - Elf32_Shdr shdrs[33]; | + Elf32_Shdr shdrs[44]; | Elf32_Dyn *dyns; | } dumpedelf_0 = { | | .ehdr = { | .e_ident = { /* (EI_NIDENT bytes) */ | /* [0] EI_MAG:*/ 0x7F,'E','L','F', | /* [4] EI_CLASS: */ 1 , /* (ELFCLASS32) */ | /* [5] EI_DATA: */ 2 , /* (ELFDATA2MSB) */ | /* [6] EI_VERSION:*/ 1 , /* (EV_CURRENT) */ | /* [7] EI_OSABI: */ 0 , /* (ELFOSABI_NONE) */ | - /* [8] EI_ABIVERSION: */ 0 , | + /* [8] EI_ABIVERSION: */ 1 , | /* [9-15] EI_PAD: */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | }, | .e_type = 2 , /* (ET_EXEC) */ | .e_machine = 8 , /* (EM_MIPS) */ | .e_version = 1 , /* (EV_CURRENT) */ | (...) Signed-off-by: Andreas K. Hüttel --- v2: Add the same fix for little endian as for big endian scripts/qemu-binfmt-conf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index e9bfeb94d3..fc2f856800 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -61,11 +61,11 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' mips_family=mips mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' mipsel_family=mips mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -- 2.34.1
[PATCH] qemu-binfmt-conf.sh: allow elf EI_ABIVERSION=1 for mips
With the command line flag -mplt and a recent toolchain, ELF binaries generated by gcc can obtain EI_ABIVERSION=1, see below, which makes, e.g., gcc three-stage bootstrap in a mips-unknown-linux-gnu qemu-user chroot fail since the binfmt-misc magic does not match anymore. qemu executes these binaries just fine, so relax the mask slightly. CHOST=mips-unknown-linux-gnu CFLAGS="-O2 -march=mips32 -mabi=32 -mplt -pipe" gcc-11.2, binutils-2.37, glibc-2.34 | /* | - * ELF dump of './prev-gcc/build/gengenrtl' | - * 29608 (0x73A8) bytes | + * ELF dump of './gcc/build/gengenrtl' | + * 54532 (0xD504) bytes | */ | | Elf32_Dyn dumpedelf_dyn_0[]; | struct { | Elf32_Ehdr ehdr; | Elf32_Phdr phdrs[12]; | - Elf32_Shdr shdrs[33]; | + Elf32_Shdr shdrs[44]; | Elf32_Dyn *dyns; | } dumpedelf_0 = { | | .ehdr = { | .e_ident = { /* (EI_NIDENT bytes) */ | /* [0] EI_MAG:*/ 0x7F,'E','L','F', | /* [4] EI_CLASS: */ 1 , /* (ELFCLASS32) */ | /* [5] EI_DATA: */ 2 , /* (ELFDATA2MSB) */ | /* [6] EI_VERSION:*/ 1 , /* (EV_CURRENT) */ | /* [7] EI_OSABI: */ 0 , /* (ELFOSABI_NONE) */ | - /* [8] EI_ABIVERSION: */ 0 , | + /* [8] EI_ABIVERSION: */ 1 , | /* [9-15] EI_PAD: */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | }, | .e_type = 2 , /* (ET_EXEC) */ | .e_machine = 8 , /* (EM_MIPS) */ | .e_version = 1 , /* (EV_CURRENT) */ | (...) Signed-off-by: Andreas K. Hüttel --- scripts/qemu-binfmt-conf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh index e9bfeb94d3..2ac2226f26 100755 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -61,7 +61,7 @@ m68k_family=m68k # FIXME: We could use the other endianness on a MIPS host. mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' -mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' mips_family=mips mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' -- 2.34.1
Re: [PATCH v2 1/1] linux-user/signal: Decode waitid si_code
Am Mittwoch, 20. Januar 2021, 22:12:30 EET schrieb Andreas K. Hüttel: > > This patch just passes the waitid status directly back to the guest. > > This works at least as well as the previous versions, so ++ from me. > > Will do more testing over the next days to see if it maybe also improves the > additional oddities I observed. > So the patch is good since it clearly resolves the linked bug. However, something else is still broken (maybe related; unchanged compared to the previous patch version). I keep seeing hanging "qemu-riscv32 /bin/bash ..." processes using 100% cpu. If I attach strace (on the host arch x86-64) to qemu, I see an infinite loop: waitid(P_ALL, -1, {}, WNOHANG|WEXITED, NULL) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0 waitid(P_ALL, -1, {}, WNOHANG|WEXITED, NULL) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0 ... Unfortunately I do not have a simple reproducer. This is somewhere in the middle of our build system... Otherwise, I can re-build glibc, gcc, binutils, make in the qemu chroot without obvious problems, with one striking strange detail - "make" refuses to run more than one concurrent process (even with MAKEOPTS="-j9"). Something is off there. -- Andreas K. Hüttel dilfri...@gentoo.org Gentoo Linux developer (council, qa, toolchain, base-system, perl, libreoffice) signature.asc Description: This is a digitally signed message part.
Re: [PATCH v2 1/1] linux-user/signal: Decode waitid si_code
> > This patch just passes the waitid status directly back to the guest. > This works at least as well as the previous versions, so ++ from me. Will do more testing over the next days to see if it maybe also improves the additional oddities I observed. Tested-by: Andreas K. Hüttel > Buglink: https://bugs.launchpad.net/qemu/+bug/1906193 > Signed-off-by: Alistair Francis > --- > v2: > - Set tinfo->_sifields._sigchld._status directly from status > > linux-user/signal.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/linux-user/signal.c b/linux-user/signal.c > index 73de934c65..7eecec46c4 100644 > --- a/linux-user/signal.c > +++ b/linux-user/signal.c > @@ -349,8 +349,7 @@ static inline void > host_to_target_siginfo_noswap(target_siginfo_t *tinfo, case TARGET_SIGCHLD: > tinfo->_sifields._sigchld._pid = info->si_pid; > tinfo->_sifields._sigchld._uid = info->si_uid; > -tinfo->_sifields._sigchld._status > -= host_to_target_waitstatus(info->si_status); > +tinfo->_sifields._sigchld._status = info->si_status; > tinfo->_sifields._sigchld._utime = info->si_utime; > tinfo->_sifields._sigchld._stime = info->si_stime; > si_type = QEMU_SI_CHLD; -- Andreas K. Hüttel dilfri...@gentoo.org Gentoo Linux developer (council, qa, toolchain, base-system, perl, libreoffice) signature.asc Description: This is a digitally signed message part.
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
Done (took a while to figure out how...) -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: Confirmed Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
Re: [PATCH v1 1/1] linux-user/signal: Decode waitid si_code
Am Samstag, 19. Dezember 2020, 20:11:13 EET schrieb Alistair Francis: > When mapping the host waitid status to the target status we previously > just used decoding information in the status value. This doesn't follow > what the waitid documentation describes, which instead suggests using > the si_code value for the decoding. This results in the incorrect values > seen when calling waitid. This is especially apparent on RV32 where all > wait calls use waitid (see the bug case). > > This patch uses the si_code value to map the waitid status. > > Buglink: https://bugs.launchpad.net/qemu/+bug/1906193 > Signed-off-by: Alistair Francis Tested-by: Andreas K. Hüttel > --- > linux-user/signal.c | 26 -- > 1 file changed, 24 insertions(+), 2 deletions(-) > > diff --git a/linux-user/signal.c b/linux-user/signal.c > index 73de934c65..b6c9326521 100644 > --- a/linux-user/signal.c > +++ b/linux-user/signal.c > @@ -305,6 +305,7 @@ static inline void > host_to_target_siginfo_noswap(target_siginfo_t *tinfo, int sig = > host_to_target_signal(info->si_signo); > int si_code = info->si_code; > int si_type; > +int status = info->si_status; > tinfo->si_signo = sig; > tinfo->si_errno = 0; > tinfo->si_code = info->si_code; > @@ -349,8 +350,29 @@ static inline void > host_to_target_siginfo_noswap(target_siginfo_t *tinfo, case TARGET_SIGCHLD: > tinfo->_sifields._sigchld._pid = info->si_pid; > tinfo->_sifields._sigchld._uid = info->si_uid; > -tinfo->_sifields._sigchld._status > -= host_to_target_waitstatus(info->si_status); > + > +/* > + * Map host to target signal numbers for the waitid family of > + * syscalls. This is similar to the functionality in > + * host_to_target_waitstatus() except we use the si_code to > + * determine the operation. > + */ > +switch (info->si_code) { > +case CLD_KILLED: > +case CLD_DUMPED: > +tinfo->_sifields._sigchld._status = > +host_to_target_signal(WTERMSIG(status)) | > + (status & ~0x7f); > +break; > +case CLD_STOPPED: > +tinfo->_sifields._sigchld._status = > +(host_to_target_signal(WSTOPSIG(status)) << 8) | > +(status & 0xff); > +break; > +default: > +tinfo->_sifields._sigchld._status = status; > +} > + > tinfo->_sifields._sigchld._utime = info->si_utime; > tinfo->_sifields._sigchld._stime = info->si_stime; > si_type = QEMU_SI_CHLD; -- Andreas K. Hüttel dilfri...@gentoo.org Gentoo Linux developer (council, qa, toolchain, base-system, perl, libreoffice) signature.asc Description: This is a digitally signed message part.
[Bug 1891748] Re: qemu-arm-static 5.1 can't run gcc
I'm still seeing this with qemu 5.2.0 armv7a-softfp-linux-gnueabi-gcc -O2 -pipe -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -Wl,-O1 -Wl,--as-needed glibc-test.c -o glibc-test Allocating guest commpage: Operation not permitted -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1891748 Title: qemu-arm-static 5.1 can't run gcc Status in QEMU: Fix Released Status in Juju Charms Collection: New Bug description: Issue discovered while trying to build pikvm (1) Long story short: when using qemu-arm-static 5.1, gcc exits whith message: Allocating guest commpage: Operation not permitted when using qemu-arm-static v5.0, gcc "works" Steps to reproduce will follow (1) https://github.com/pikvm/pikvm/blob/master/pages/building_os.md To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1891748/+subscriptions
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
Just as a general remark, while this specific problem seems to be solved, there may still be issues surrounding waitid(). (With this patch applied, in a rather complex environment I see bash processes hanging in an infinite loop, with waitid involved. I am working on isolating the problem and providing a simple test case, but so far I have not even found the code triggering it.) -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: Confirmed Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
After applying this patch on top of qemu-5.2.0, I can confirm that it fixes the problem. Thank you!! -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: New Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
Thanks a lot! Will test and post the result on monday when I'm back home. -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: New Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
Here's qemu's own strace log: farino ~ # /usr/bin/qemu-riscv32 -strace /chroot/riscv-ilp32/tmp/wait-test-short 10123 brk(NULL) = 0x00073000 10123 brk(0x00073880) = 0x00073880 10123 uname(0x407ffed8) = 0 10123 readlinkat(AT_FDCWD,"/proc/self/exe",0x407feff0,4096) = 39 10123 brk(0x00094880) = 0x00094880 10123 brk(0x00095000) = 0x00095000 10123 mprotect(0x0006e000,8192,PROT_READ) = 0 10123 clone(CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,child_stack=0x,parent_tidptr=0x,tls=0x,child_tidptr=0x00073068) = 10125 10123 clone(CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,child_stack=0x,parent_tidptr=0x,tls=0x,child_tidptr=0x00073068) = 0 10125 exit_group(42) 10123 waitid(0,-1,0x407fff8c,0x4) = 0 10123 statx(1,"",AT_EMPTY_PATH,STATX_BASIC_STATS,0x407ff8e8) = 0 child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 10123 write(1,0x73ad0,74) = 74 10123 exit_group(0) -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: New Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
Here's the (abbreviated) output of strace'ing qemu: farino ~ # strace -f /usr/bin/qemu-riscv32 /chroot/riscv-ilp32/tmp/wait-test-short execve("/usr/bin/qemu-riscv32", ["/usr/bin/qemu-riscv32", "/chroot/riscv-ilp32/tmp/wait-tes"...], 0x7ffd95fb1330 /* 40 vars */) = 0 [...] [pid 16569] uname({sysname="Linux", nodename="farino", ...}) = 0 [pid 16569] lstat("/chroot", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 [pid 16569] lstat("/chroot/riscv-ilp32", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0 [pid 16569] lstat("/chroot/riscv-ilp32/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0 [pid 16569] lstat("/chroot/riscv-ilp32/tmp/wait-test-short", {st_mode=S_IFREG|0755, st_size=445632, ...}) = 0 [pid 16569] mmap(0x413f1000, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x413f1000 [pid 16569] mprotect(0x413eb000, 8192, PROT_READ) = 0 [pid 16569] rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 [pid 16569] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x1339710) = 16571 strace: Process 16571 attached [pid 16571] set_robust_list(0x1339720, 24 [pid 16569] rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 [pid 16571] <... set_robust_list resumed>) = 0 [pid 16569] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 16571] rt_sigprocmask(SIG_SETMASK, ~[ILL FPE SEGV RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0 [pid 16571] rt_sigprocmask(SIG_BLOCK, ~[], ~[ILL FPE KILL SEGV STOP RTMIN RT_1], 8) = 0 [pid 16571] clone(child_stack=0x7fe5b73871f0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tid=[16572], tls=0x7fe5b7387640, child_tidptr=0x7fe5b7387910) = 16572 [pid 16571] rt_sigprocmask(SIG_SETMASK, ~[ILL FPE KILL SEGV STOP RTMIN RT_1], NULL, 8) = 0 [pid 16571] rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0 [pid 16571] gettid()= 16571 [pid 16571] rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0 [pid 16571] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 [pid 16569] waitid(P_ALL, -1, [pid 16571] exit_group(42) = ? strace: Process 16572 attached [pid 16572] +++ exited with 42 +++ [pid 16571] +++ exited with 42 +++ [pid 16569] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=16571, si_uid=0, si_status=42, si_utime=3472328296226648184, si_stime=3475143045726351408}, WEXITED, NULL) = 0 [pid 16569] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=16571, si_uid=0, si_status=42, si_utime=0, si_stime=0} --- [pid 16569] statx(1, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFCHR|0600, stx_size=0, ...}) = 0 [pid 16569] write(1, "child wants to return 42 (0x2A),"..., 74child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 ) = 74 [pid 16569] brk(0x13c1000) = 0x13c1000 [pid 16569] brk(0x13c) = 0x13c [pid 16569] exit_group(0) = ? [pid 16570] <... futex resumed>)= ? [pid 16570] +++ exited with 0 +++ +++ exited with 0 +++ -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: New Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
I can confirm that the same binary works fine with qemu system emulation: (riscv-ilp32 qemu) (none) /tmp # ./wait-test-short (riscv-ilp32 qemu) (none) /tmp # -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: New Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
[Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
This is the (statically linked) binary resulting from the source; with it the problem can be demonstrated "standalone", without any other rv32 libraries or a complete chroot, just running the binary with qemu- riscv32. Generated with (riscv-ilp32 chroot) farino /tmp # gcc -static -o wait-test-short -g wait-test-short.c ** Attachment added: "wait-test-short" https://bugs.launchpad.net/qemu/+bug/1906193/+attachment/5441136/+files/wait-test-short -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1906193 Title: riscv32 user mode emulation: fork return values broken Status in QEMU: New Bug description: When running in a chroot with riscv32 (on x86_64; qemu git master as of today): The following short program forks; the child immediately returns with exit(42). The parent checks for the return value - and obtains 40! gcc-10.2 === #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (r!=42) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42); } } } === (riscv-ilp32 chroot) farino /tmp # ./wait-test-short child wants to return 42 (0x2A), parent received 40 (0x28), difference -2 === (riscv-ilp32 chroot) farino /tmp # gcc --version gcc (Gentoo 10.2.0-r1 p2) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE. (riscv-ilp32 chroot) farino /tmp # ld --version GNU ld (Gentoo 2.34 p6) 2.34.0 Copyright (C) 2020 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
Re: riscv32 wait() problem, qemu or glibc?
Am Donnerstag, 17. September 2020, 00:05:10 EEST schrieb Alistair Francis: > On Wed, Sep 16, 2020 at 2:09 PM Andreas K. Hüttel wrote: > > > My guess is that somewhere in QEMU the types don't match what RV32 is > > > using. It's probably worth printing out the size, alignment and value > > > of everything at every stage and see what breaks. > > > > Thanks. > > Sorry I can't be more helpful. Hopefully one day I will look into it, > but it's not a high priority. No problem at all. I'm mostly going to postpone this now in favour of autobuilding bootable images (which needs some non-riscv specific preparation). Last thing I still did overnight was run the glibc testsuite in quemu-riscv32 user emulation. The summary is below (and as suspected a bit of a massacre); I'll look at the details later sometime. If anyone else wants to poke at it, I've tarred up the full glibc build dir and uploaded it together with the build log, see https://dev.gentoo.org/~dilfridge/rv32-testing/ UNSUPPORTED: crypt/cert FAIL: debug/tst-backtrace4 FAIL: debug/tst-backtrace5 FAIL: debug/tst-backtrace6 FAIL: elf/check-localplt UNSUPPORTED: elf/tst-dlopen-self-container UNSUPPORTED: elf/tst-dlopen-tlsmodid-container XPASS: elf/tst-latepthread UNSUPPORTED: elf/tst-ldconfig-bad-aux-cache UNSUPPORTED: elf/tst-ldconfig-ld_so_conf-update UNSUPPORTED: elf/tst-pldd XPASS: elf/tst-protected1a XPASS: elf/tst-protected1b FAIL: iconv/tst-iconv_prog UNSUPPORTED: io/tst-copy_file_range UNSUPPORTED: io/tst-getcwd-abspath FAIL: libio/tst-atime UNSUPPORTED: locale/tst-localedef-path-norm UNSUPPORTED: localedata/tst-localedef-hardlinks FAIL: malloc/tst-dynarray-fail FAIL: malloc/tst-dynarray-fail-mem FAIL: malloc/tst-interpose-nothread FAIL: malloc/tst-interpose-static-nothread FAIL: malloc/tst-interpose-static-thread FAIL: malloc/tst-interpose-thread FAIL: malloc/tst-mallocfork2 UNSUPPORTED: malloc/tst-mallocstate FAIL: math/test-double-j1 FAIL: math/test-double-y0 UNSUPPORTED: math/test-fesetexcept-traps UNSUPPORTED: math/test-fexcept-traps FAIL: math/test-float-asinh FAIL: math/test-float-cos FAIL: math/test-float-cosh FAIL: math/test-float-erfc FAIL: math/test-float-exp FAIL: math/test-float-j0 FAIL: math/test-float-j1 FAIL: math/test-float-lgamma FAIL: math/test-float-sin FAIL: math/test-float-tgamma FAIL: math/test-float-y0 FAIL: math/test-float32-asinh FAIL: math/test-float32-cos FAIL: math/test-float32-cosh FAIL: math/test-float32-erfc FAIL: math/test-float32-exp FAIL: math/test-float32-j0 FAIL: math/test-float32-j1 FAIL: math/test-float32-lgamma FAIL: math/test-float32-sin FAIL: math/test-float32-tgamma FAIL: math/test-float32-y0 FAIL: math/test-float32x-j1 FAIL: math/test-float32x-y0 FAIL: math/test-float64-j1 FAIL: math/test-float64-y0 UNSUPPORTED: math/test-matherr UNSUPPORTED: math/test-matherr-2 UNSUPPORTED: math/test-nearbyint-except UNSUPPORTED: math/test-nearbyint-except-2 FAIL: misc/test-errno-linux FAIL: misc/tst-clone2 FAIL: misc/tst-clone3 FAIL: misc/tst-gettid-kill FAIL: misc/tst-glibcsyscalls FAIL: misc/tst-memfd_create FAIL: misc/tst-mlock2 UNSUPPORTED: misc/tst-ofdlocks-compat UNSUPPORTED: misc/tst-pkey FAIL: misc/tst-sigcontext-get_pc UNSUPPORTED: misc/tst-ttyname UNSUPPORTED: nptl/test-cond-printers UNSUPPORTED: nptl/test-condattr-printers UNSUPPORTED: nptl/test-mutex-printers UNSUPPORTED: nptl/test-mutexattr-printers UNSUPPORTED: nptl/test-rwlock-printers UNSUPPORTED: nptl/test-rwlockattr-printers FAIL: nptl/tst-align-clone FAIL: nptl/tst-cancel-self-canceltype FAIL: nptl/tst-cancel17 FAIL: nptl/tst-cancel21 FAIL: nptl/tst-cancel21-static FAIL: nptl/tst-cancel24 FAIL: nptl/tst-cancel24-static FAIL: nptl/tst-cancelx16 FAIL: nptl/tst-cancelx17 FAIL: nptl/tst-cancelx18 FAIL: nptl/tst-cancelx20 FAIL: nptl/tst-cancelx21 FAIL: nptl/tst-cancelx4 FAIL: nptl/tst-cancelx5 FAIL: nptl/tst-cleanupx4 FAIL: nptl/tst-cond-except FAIL: nptl/tst-cond24 FAIL: nptl/tst-cond25 FAIL: nptl/tst-getpid1 UNSUPPORTED: nptl/tst-mutexpi5 UNSUPPORTED: nptl/tst-mutexpi5a UNSUPPORTED: nptl/tst-mutexpi9 FAIL: nptl/tst-oncex3 FAIL: nptl/tst-oncex4 UNSUPPORTED: nptl/tst-pthread-getattr FAIL: nptl/tst-robust-fork FAIL: nptl/tst-robust1 FAIL: nptl/tst-robust2 FAIL: nptl/tst-robust3 FAIL: nptl/tst-robust4 FAIL: nptl/tst-robust5 FAIL: nptl/tst-robust6 FAIL: nptl/tst-robust7 FAIL: nptl/tst-robust8 FAIL: nptl/tst-robust9 XPASS: nptl/tst-stack4 UNSUPPORTED: nss/tst-nss-db-endgrent UNSUPPORTED: nss/tst-nss-db-endpwent UNSUPPORTED: nss/tst-nss-files-alias-leak UNSUPPORTED: nss/tst-nss-files-alias-truncated UNSUPPORTED: nss/tst-nss-files-hosts-erange UNSUPPORTED: nss/tst-nss-files-hosts-getent UNSUPPORTED: nss/tst-nss-files-hosts-long UNSUPPORTED: nss/tst-nss-test3 FAIL: posix/test-errno FAIL: posix/tst-fexecve UNSUPPORTED: posix/tst-glob_lstat_compat FAIL: posix/tst-posix_spawn-setsid FAIL: posix/tst-spawn2 FAIL: posix/tst-spawn4 UNSUPPORTED: posix/tst-spawn4-compat UNSUPPORTED: posix/tst-sysconf-empty-c
Re: riscv32 wait() problem, qemu or glibc?
> My guess is that somewhere in QEMU the types don't match what RV32 is > using. It's probably worth printing out the size, alignment and value > of everything at every stage and see what breaks. Thanks. > AFAIK RV32 linux-user mode is pretty much un-tested. So their might be > all sorts of issues with it unfortunately. Would you consider qemu system mode more reliable? I need to prepare some bootable riscv gentoo images eventually anyway. Might as well try a riscv32 one for comparison then if that is more promising. -- Andreas K. Hüttel dilfri...@gentoo.org Gentoo Linux developer (council, qa, toolchain, base-system, perl, libreoffice) signature.asc Description: This is a digitally signed message part.
Re: riscv32 wait() problem, qemu or glibc?
chroot) farino /tmp # === #include #include #include #include main(c, v) int c; char **v; { for(int z=0; z<255; z++){ pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit(z); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); if (z!=r) { printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",z,z,r,r,r-z); } } } } === Am Montag, 14. September 2020, 11:14:16 EEST schrieb Andreas K. Hüttel: > Hi, > > first of all, sorry for crossposting, but I'm dealing with many moving and > experimental parts here... > > Situation: riscv32 (ilp32) qemu-user [1] chroot, Linux [2], glibc [3], gcc > [4] > > The following small program outputs "child exited with status 40", which is > rather unexpected (it should be 42). Any idea what is going on? > > (This is a simplified version of code in a configure test. The test has > other potential issues [5], but in any case it cant produce useful results > on riscv32 right now.) > > TIA, > Andreas > > > #include > #include > #include > #include > > main(c, v) > int c; > char **v; > { > pid_t pid, p; > int s, i, n; > > s = 0; > pid = fork(); > if (pid == 0) > exit (42); > > /* wait for the process */ > p = wait(); > if (p != pid) > exit (255); > > if (WIFEXITED(s)) > { > int r=WEXITSTATUS(s); > printf("child exited with status %i\n",r); > } > } > > > > [1] qemu built from git master, Sep 12, 2020 16:30:37 EEST > [2] host kernel is 5.8.8 > [3] glibc-2.32 with the rv32 patch series backported from master > [4] (Gentoo 10.2.0-r1 p2) > [5] https://lists.gnu.org/archive/html/bug-bash/2020-09/msg00033.html -- Andreas K. Hüttel dilfri...@gentoo.org Gentoo Linux developer (council, qa, toolchain, base-system, perl, libreoffice) signature.asc Description: This is a digitally signed message part.
riscv32 wait() problem, qemu or glibc?
Hi, first of all, sorry for crossposting, but I'm dealing with many moving and experimental parts here... Situation: riscv32 (ilp32) qemu-user [1] chroot, Linux [2], glibc [3], gcc [4] The following small program outputs "child exited with status 40", which is rather unexpected (it should be 42). Any idea what is going on? (This is a simplified version of code in a configure test. The test has other potential issues [5], but in any case it cant produce useful results on riscv32 right now.) TIA, Andreas #include #include #include #include main(c, v) int c; char **v; { pid_t pid, p; int s, i, n; s = 0; pid = fork(); if (pid == 0) exit (42); /* wait for the process */ p = wait(); if (p != pid) exit (255); if (WIFEXITED(s)) { int r=WEXITSTATUS(s); printf("child exited with status %i\n",r); } } [1] qemu built from git master, Sep 12, 2020 16:30:37 EEST [2] host kernel is 5.8.8 [3] glibc-2.32 with the rv32 patch series backported from master [4] (Gentoo 10.2.0-r1 p2) [5] https://lists.gnu.org/archive/html/bug-bash/2020-09/msg00033.html -- Andreas K. Hüttel dilfri...@gentoo.org Gentoo Linux developer (council, qa, toolchain, base-system, perl, libreoffice) signature.asc Description: This is a digitally signed message part.