Old problem but hard to kill

J. Johnston jjohnstn@redhat.com
Mon Jul 22 12:14:00 GMT 2002

Wolfgang Fritz wrote:
> mmxlee@263.net wrote:
> > Hello,
> >
> > Yes , I have some problem with newlib , again it's for a mips-tx39-elf target.
> >
> > The newlib is compiled smoothly but just don't work,
> > when I compile a simple "hello.c" , it always prompt the same error:
> >
> > in function '_sbrk'
> > undefined reference to `sbrk'
> >
> > in function '_read'
> > undefined reference to 'read'
> >
> > Then I compile the newlib again with the -DREENTRANT-PROVIDED, then the error becomes:
> >
> > in function '_sbrk_r'
> > undefined reference to 'sbrk'
> >
> > in function '_read_r'
> > undefined reference to 'read'
> >
> > seems no help.
> >
> > I can't use a C compiler without a newlib support, but how can I provide a suitable library for my compiler...?
> >
> I had a similar problem with a special m68k target with 68LC302
> processor. Some basic functions like read, sbrk etc. are too target
> specific and therefore not included in newlib itself. If you are lucky,
> someone has written them for your target, if not, you have to write them
> yourself. To make this easier, the "libgloss" library provides basic
> versions of these functions for very simple targets. For the m68k target
>     it was called "libnosys". If you have it for your target too, you
> may add it to your link command and at least get a successful link.
> There is some documentation available for this, but I don't where I it
> comes from. It appeared on my computer during the build of the GNU
> toolchain. Maybe it was generated during the gcc build. It's called
> "Embed with GNU" and accessible via "info" on my linux box.

For mips, you should specify an ld script when you compile/link.  You can do so
via the -T option (e.g. mips-elf-gcc -Tidt.ld hello.c).  There are a number of ld scripts available in the libgloss/mips directory.  See if any of the
available choices are applicable to your situation and if not, you can either add your own script (and/or library) or use the
libnosys library instead.  The libnosys library is built with libgloss and is a set of stubs
for the various syscalls that newlib uses.  The majority of the stubs return failure
but there is a basic sbrk call which does support the malloc family of routines.  To use 
libnosys, add -lnosys to your compile/link.

The source to the document referred to above by Wolfgang is libgloss/doc/porting.texi.
If you make info for libgloss you can get the info version of the document.

BTW, your configuration triplet isn't proper.  It should be mipstx39-elf (no dash
between mips and tx39).

-- Jeff J.

More information about the Newlib mailing list