This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: libgloss depends on libc for __errno
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Patrick Mansfield <patmans at us dot ibm dot com>
- Cc: newlib at sourceware dot org
- Date: Fri, 02 Feb 2007 20:18:24 -0500
- Subject: Re: libgloss depends on libc for __errno
- References: <20070202230157.GA23940@us.ibm.com>
Patrick Mansfield wrote:
Hi -
Code in libgloss references errno in many newlib libgloss files across
archs, but errno is located in libc.
Technically, should errno (and by reference) reent be in libgloss?
Is newlib libgloss ever used without its libc?
Historically, libgloss was created to be a companion library to newlib
to contain the small number of syscalls newlib requires. This allowed
multiple board packages to be set up in the case where a platform had
multiple configurations.
So, yes, newlib and libgloss are definitely cousins. Note that libgloss
is shipped as part of newlib and not on its own.
Now, on to a more complex explanation regarding reentrancy, errno, and
libgloss.
There are multiple ways to set up libgloss depending on whether you have
reentrant syscalls or not. Read libc/include/reent.h for a brief
description on this.
After that, you need to look at the libc/reent code. For example, a
skimmed down version of readr.c follows that gets compiled if the
platform has not set the magic newlib flag REENTRANT_SYSCALLS_PROVIDED:
/* We use the errno variable used by the system dependent layer. */
#undef errno
extern int errno;
_ssize_t
_DEFUN (_read_r, (ptr, fd, buf, cnt),
struct _reent *ptr _AND
int fd _AND
_PTR buf _AND
size_t cnt)
{
_ssize_t ret;
errno = 0;
if ((ret = (_ssize_t)_read (fd, buf, cnt)) == -1 && errno != 0)
ptr->_errno = errno;
return ret;
}
Note that the _read_r routine is undef'ing newlib's definition in
errno.h. The libgloss layer is given two choices. If it is
single-threaded, it can simply use the external int errno to indicate an
errno situation and this will get copied into the reentrant struct.
This is what libnosys does (stubbed libgloss library).
The other choice is what spu and a number of platforms do which is to
simply use newlib's errno.h which will modify errno directly for the
default reentrant struct OR if the platform supplies a __getreent()
routine, it can modify errno for the current thread automatically.
-- Jeff J.