This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: brk syscall in libgloss/rs6000/simulator.S and libgloss/m68k/simulator.S


Rory,

You should not be using nor changing the simulator.S code. It is designed to work with the existing generic testing simulator (found in gdb package last time I checked). The simulator is used for running the gcc testsuite among other things. For such a simulator, the syscalls are arbitrary - i.e. the simulator can define any syscall number system it wants to. It simply translates these into local syscalls on the system running the simulator. In this case, the powerpc simulator has specified syscall 17 as brk so it translates this to a local brk call when it sees it. The simulator also has the liberty of arbitrarily defining how a syscall is even implemented. It may use a rarely used insn, a special trap, etc.., whatever it wants to. This may or may not correspond to what is actually used in a linux system. You cannot expect to run that executable on a real powerpc system or a third-party simulator/emulator.

The correct way to handle this is to create a new libgloss library under libgloss/rs6000. You will have to create an ld script that is to be used instead of -msim (the compiler won't internally know to link with your new libgloss library). There was at one time a linux library in rs6000 but it no longer exists and I can't say whether or not it ever worked.

-- Jeff J.

Rory Yorke wrote:
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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]