Hi,
After successfully building a PowerPC cross-compiling binutils and
gcc+newlib, I had the following problem when running PowerPC binaries
under qemu:
rory@segserver:~/hack/c/hello$ cat simplesum.c
#include <stdio.h>
int
main()
{
double y=1+2;
printf("1+2 = %g\n",y);
return 0;
}
rory@segserver:~/hack/c/hello$ powerpc-linux-elf-gcc -msim simplesum.c
-o simplesum
rory@segserver:~/hack/c/hello$ qemu-ppc simplesum
qemu: Unsupported syscall: 17
qemu: Unsupported syscall: 17
Invalid data memory access: 0x00000014
Invalid segfault errno (2000000)
qemu: uncaught target signal 11 (Segmentation fault) - exiting
According to the /usr/include/asm-i386/unistd.h on my machine, system
call 17 is 'break'; according to 'man 2 break', this system call is
unimplemented. I guessed that what was really wanted was brk, which
is system call 45. A corresponding change to the function brk in
libgloss/rs6000/simulator.S gave me a working result, i.e.,
rory@segserver:~/hack/c/hello$ powerpc-linux-elf-gcc -msim simplesum.c
-o simplesum
rory@segserver:~/hack/c/hello$ qemu-ppc simplesum
1+2 = 3
I don't really understand what is going on here: I don't know what the
break system call is (Google didn't help much), or why it's
unimplemented, or why it's called in libgloss and not brk. Perhaps
there is some other target for which this is the correct behaviour.
Regardless, this fix Works On My Machine, and I thought it might be
handy for others to know.
The patch attached is against newlib 1.12.0; I checked the CVS trunk,
and
libgloss/rs6000/simulator.S still calls syscall 17. The patch alters
libgloss/m68k/simulator.S in a similar manner; I haven't tested with
an m68k target. I grepped for brk in the entire libgloss tree, but I
didn't understand the other hits.
Finally, some details on my cross-compile setup; the cross-compile
tools are:
binutils 2.17.50.0.15.20070418
gcc 2.95.3
newlib 1.12.0
Host is an Ubuntu 6.06 system, with Ubuntu-provided gcc 4.0.3 and
binutils 2.16.91 20060118.
binutils config:
../../binutils-2.17.50.0.15/configure --target=powerpc-linux-elf
--prefix=/home/rory/powerpc-cross
gcc/newlib config:
../../gcc-2.95.3/configure
--with-gcc-version-trigger=/home/rory/work/adarter/cross-compile2/gcc-2.
95.3/gcc/version.c --host=i686-pc-linux-gnu --target=powerpc-linux-elf
--prefix=/home/rory/powerpc-cross --with-newlib
--program-prefix=powerpc-linux-elf- --norecursion
(that last is from config.status; my invocation was simpler).
gcc was built with newlib and libgloss symlinks in the gcc top-level
source directory.
I hope this is of some use.
Regards,
Rory