Advice on a new port of newlib

Jeff Johnston
Fri Aug 19 16:43:00 GMT 2005

Warren Toomey wrote:
> Hi all, after looking at glibc and uClib, I have been pointed at
> newlib which seems exactly what I'm after. What I am trying to do
> is tricky, so I thought I would ask for some advice before I begin.
> I've read through the available docs and the FAQ.
> I want to port newlib to FMIOS to replace its minimal libc. FMIOS is a
> microkernel system, which provides a set of libraries to emulate POSIX,
> as it doesn't have POSIX system calls [].
> Other features/issues: native a.out at present, no shared libs, no
> networking, no pthreads, gcc 2.7.1.
> I have modified the system to support statically-linked ELF binaries.
> At present, I can recompile all of userland and the kernel using
> the ELF compiler on Linux or FreeBSD, including the existing libc.
> Now I want to build gcc 3.4 to produce a native ELF compiler.
> Before I try to recompile gcc, I thought I would improve the libc,
> hence newlib. The native compiler only supports a.outs, so I want
> to build newlib for FMIOS using the FreeBSD ELF compiler.
> I'm going to have to create libgloss/fmios. I'm assuming that in
> here I will need to place the code for the non-POSIX system calls,
> plus the library code that emulates POSIX system calls. I guess
> crt0.s goes here too. Does this all sound right? And what's the difference
> between libgloss/<platform> and newlib/libc/sys/<platform>?

Libgloss contains the system call layer for an embedded platform.  For 
generic newlib, there is only a small number of syscalls you "need" to 
provide.  See the manual off the web-site. 
The sys directory is for OSes (e.g. linux).  In the past, some platforms 
used this as libgloss, but that is historical and not current practice.

> Will newlib be able to be built on FreeBSD, with FMIOS as the target?
> Is there a stage in newlib compilation where a binary is created
> and then executed?  Do I have to treat this as cross-compilation?
> How do I ensure the compilation uses the FMIOS headers and not the
> FreeBSD /usr/include?

By default, gcc does not build newlib natively.  For certain cases such 
as x86-linux, native newlib is supported and actually required.  In the 
linux case, newlib overrides some headers but must still use some of the 
installed headers; thus, it must be built natively.  When configuring, 
the --with-newlib option needs to be specified to force building of the 
native newlib and for gcc to use the newlib header files.  In your case, 
you must determine if you require system header files or if newlib plus 
gcc can provide them all.

> FMIOS doesn't have link(2). Do I need to put an empty link() stub
> in libgloss/fmios? Will this affect the compilation?

You can either add a minimal stub (in the syscalls section of the docs) 
or use -lnosys when you link.  Libnosys is a stub library for general usage.

> Is there anything else I should think about before starting? Any gotchas
> for this situation?
> Many thanks in advance for your advice,
> 	Warren Toomey

More information about the Newlib mailing list