-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libc: Fix include order #84943
base: main
Are you sure you want to change the base?
libc: Fix include order #84943
Conversation
<zephyr/sys/errno_private.h> depends on errno being defined. With strict compiler warnings enabled, this causes a build failure. Signed-off-by: Yuval Peress <[email protected]>
@@ -28,14 +28,15 @@ | |||
* @{ | |||
*/ | |||
|
|||
/* errno_private.h depends on errno being defined first. */ | |||
#define errno (*z_errno()) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense to me -- the only place errno_private.h uses errno directly is in defining z_errno
, so this define would result in a circular definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see if I can retrace this (it took me a long time to get Zephyr to build with Bazel so this change was pretty old.
lib/libc/minimal/include/errno.h
includeszephyr/sys/errno_private.h
zephyr/sys/errno_private.h
withCONFIG_LIBC_ERRNO
includeserrno.h
which is a no-op since we have already#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_ERRNO_H_
- Then
zephyr/sys/errno_private.h
definesz_errno()
which returns&errno
buterrno
is only defined afterzephyr/sys/errno_private.h
is included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious to know why Zephyr hasn't encountered this error before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't want errno
defined as (*z_errno())
when we define z_errno
as that's just an infinite loop. If you want to use CONFIG_LIBC_ERRNO, you need the minimal C library to have its own definition of errno, presumably as a global variable. Probably something like this:
#ifdef CONFIG_LIBC_ERRNO
int errno;
#endif
#include <zephyr/sys/errno_private.h>
#define errno (*z_errno())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me rebase and try without this commit. I'll report back tonight.
I ran into an issue with the include order when building Zephyr using Bazel. This seems to check out when I walked through the include order, there's a circular dependency here that's resolved by moving the definition up.