[uClibc]errno confusion

Miles Bader miles at lsi.nec.co.jp
Wed Aug 14 04:57:43 UTC 2002


I noticed that a function compiled inside libc was being treated by the
compiler as a leaf function, whereas compiled outside libc, it wasn't.

The difference turned out to be that the function was writing to
`errno', and when compiled inside libc, this was treated as a simple
variable write because _LIBC was defined, whereas outside libc, it was
treated as `(*errno_location()) = ...'.

This is because of the following defines in common/bits/errno.h:

   #  if defined _LIBC
   /* We wouldn't need a special macro anymore but it is history.  */
   #   define __set_errno(val) (*__errno_location ()) = (val)
   #  endif /* _LIBC */

   #  if !defined _LIBC || defined _LIBC_REENTRANT
   /* When using threads, errno is a per-thread value.  */
   #   define errno (*__errno_location ())
   #  endif
   # endif /* !__ASSEMBLER__ */
   #endif /* _ERRNO_H */

However, my system (v850) doesn't support threading to the best of my
knowledge, so this seemed a bit silly.

So, my questions are:

  (1) Should it be dragging in this thread-safe definition of `errno',
      even though __UCLIBC_HAS_THREADS__ is undefined?  Wouldn't it be
      OK to use a simple variable for `errno' on such systems?

  (2) Is code _inside_ libc supposed to always use __set_errno to set
      errno (some code, e.g. linux/asm/unistd.h, assumes otherwise)?
      That's what seems to be implied by the above defines in
      common/bits/errno.h, which avoid #defining `errno' if _LIBC is
      defined.

Thanks,

-Miles
-- 
Yo mama's so fat when she gets on an elevator it HAS to go down.



More information about the uClibc mailing list