qemu-hppa log10 produces incorrect results
Host environment
- Operating system: Gentoo Linux (x86-64)
- OS/kernel version: 6.12.16-gentoo-dist
- Architecture: x86-64
- QEMU flavor: qemu-hppa
- QEMU version: 10.0.3
- systemd-nspawn environment running qemu via binfmt-misc
Emulated/Virtualized environment
- Operating system: Gentoo Linux (hppa1.1)
- Architecture: hppa1.1
Description of problem
The build of flex fails in the emulated environment (with stage1flex aborting), see https://bugs.gentoo.org/962007
Reducing the code to a minimal reproducer led to the following program:
#include <math.h>
#include <stdio.h>
int main() {
for (int i = 1; i <= 50; i++) {
int c=ceil (log10(i));
printf("%d %d\n", i, c);
}
}
It can be compiled with
dilfridge@dilfridge-hppa ~ $ gcc -march=1.1 -o mylist mylist.c -lm -static
(static or dynamic linking makes no difference, indicating that glibc is not the problem).
Running natively on a PA-RISC machine, the output is
g-dilfridge@matoro-hppadev ~ $ ./mylist
1 0
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 2
12 2
13 2
14 2
15 2
16 2
17 2
18 2
19 2
20 2
21 2
22 2
23 2
24 2
25 2
26 2
27 2
28 2
29 2
30 2
31 2
32 2
33 2
34 2
35 2
36 2
37 2
38 2
39 2
40 2
41 2
42 2
43 2
44 2
45 2
46 2
47 2
48 2
49 2
50 2
Under qemu-hppa, the output is
dilfridge@dilfridge-hppa ~ $ ./mylist
1 0
2 1
3 2
4 2
5 3
6 3
7 3
8 3
9 4
10 4
11 4
12 4
13 4
14 4
15 4
16 4
17 -3643122
18 5
19 5
20 5
21 5
22 5
23 5
24 5
25 5
26 5
27 5
28 5
29 5
30 5
31 5
32 5
33 -1821558
34 -3643121
35 6
36 6
37 6
38 6
39 6
40 6
41 6
42 6
43 6
44 6
45 6
46 6
47 6
48 6
49 6
50 6
This may be related to #625