This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Multiple conflicting errno.h libraries

Working with nRF9160 in Zephyr, I've recently noticed that there are multiple conflicting definition of the errno.h values available, and I'm pretty sure I've seen both in use at various times.

Most of Zephyr appears to use the ones available in zephyr/lib/libc/minimal/include/errno.h

The NRFX library politely defines it's own variants with NRF_ prefixes in nrfxlib/bsdlib/include/nrf_errno.h

However, the gnuarmemb toolchain provides it's own version in gnuarmemb2018q2/arm-none-eabi/include/sys/errno.h which DON'T MATCH and I've seen evidence of some libraries using them, including the NRFX BSD library.

For example, ETIMEDOUT is 60 in the Zephyr's variants, but 116 in the gnuarmemb variant, and I just had a NRFX offloaded recv() call fail with errno=116.  (Specifically in the download_client library)

This needs to be rectified...

  • Hi,

     

    I made a small routine to print your libc wrt. errno's:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #define ERRNO_STRINGIFY(ERR) \
    do {printk("Errno %s has value %d\n", #ERR, ERR);} \
    while (0)
    void errno_checker(void)
    {
    #if defined(CONFIG_NEWLIB_LIBC) && defined(_NEWLIB_VERSION)
    printk("Newlib version %s\n", _NEWLIB_VERSION);
    #elif defined(ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_ERRNO_H_)
    printk("Zephyr Minimal libc\n");
    #else
    printk("Not able to resolve libc used\n");
    #endif
    ERRNO_STRINGIFY(EPERM );
    ERRNO_STRINGIFY(ENOENT );
    ERRNO_STRINGIFY(ESRCH );
    ERRNO_STRINGIFY(EINTR );
    ERRNO_STRINGIFY(EIO );
    ERRNO_STRINGIFY(ENXIO );
    ERRNO_STRINGIFY(E2BIG );
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Are you certain that this is related to the codebase? Newlib has different definitions of errno, compared to zephyrs minimal libc, and ETIMEDOUT is 116 in newlib v3.0.0:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    Newlib version 3.0.0
    Errno EPERM has value 1
    Errno ENOENT has value 2
    Errno ESRCH has value 3
    Errno EINTR has value 4
    Errno EIO has value 5
    Errno ENXIO has value 6
    Errno E2BIG has value 7
    Errno ENOEXEC has value 8
    Errno EBADF has value 9
    Errno ECHILD has value 10
    Errno EAGAIN has value 11
    Errno ENOMEM has value 12
    Errno EACCES has value 13
    Errno EFAULT has value 14
    Errno ENOTEMPTY has value 90
    Errno EBUSY has value 16
    Errno EEXIST has value 17
    Errno EXDEV has value 18
    Errno ENODEV has value 19
    Errno ENOTDIR has value 20
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Which looks consistent with the errno in sys (this file is old, but seems to be unchanged compared to the sourceware git repo):

    https://github.com/eblot/newlib/blob/master/newlib/libc/include/sys/errno.h#L147

     

    Does your prj.conf/.config set "CONFIG_NEWLIB_LIBC=y"?

     

    Kind regards,

    Håkon

  • Does your prj.conf/.config set "CONFIG_NEWLIB_LIBC=y"?

    Yep.  I forgot we *just* added it for lwm2m_carrier, and that's probably why this looked out of place to me.  The socket offload layer is probably converting from NRF_ETIMEDOUT to the newlib ETIMEDOUT just like it's supposed to..

    Thank you for the hint.