-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Remove explicit -D_POSIX_C_SOURCE global compiler options when building with picolibc #67040
Remove explicit -D_POSIX_C_SOURCE global compiler options when building with picolibc #67040
Conversation
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
a682c7a
to
550a768
Compare
Ideally, the one for the toolchain would depend on the version of picolibc provided, but I have no idea how to make that work. |
4d7c06b
to
8ed02d5
Compare
8ed02d5
to
731ed67
Compare
@@ -6,7 +6,7 @@ | |||
|
|||
#define DT_DRV_COMPAT espressif_esp32_wifi | |||
|
|||
#define _POSIX_C_SOURCE 200809 | |||
#define _POSIX_C_SOURCE 200809L |
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 can be removed as there is no non-standard posix call in Espressif's sources.
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.
Thanks! I'll mix that in once I've got things building.
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.
Looks like that worked!
6e57e5b
to
3bb9463
Compare
The compliance check failure is from the |
I guess adding it to the Zephyr API is a bit against the point (of these rules https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#rule-a-5-c-standard-library-usage-restrictions-in-zephyr-codebase ) |
Oh, that's a very interesting idea. While we say that the Zephyr C library API includes a few POSIX extensions, we simply require that applications using those functions request them through the "normal" mechanism -- One downside is that this would make it very difficult to detect code which is using non-ISO C APIs which are not part of the Zephyr API. Another is that we would have to stick |
@@ -133,7 +133,7 @@ if (CONFIG_GPROF) | |||
target_link_options(native_simulator INTERFACE "-pg") | |||
endif() | |||
|
|||
zephyr_compile_definitions(_POSIX_C_SOURCE=200809 _XOPEN_SOURCE=600 _XOPEN_SOURCE_EXTENDED) | |||
zephyr_compile_definitions(_POSIX_C_SOURCE=200809L _XOPEN_SOURCE=600 _XOPEN_SOURCE_EXTENDED) |
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.
Darn - I guess this line might still be an issue because it changes cflags globally for the entire build, which would violate rules A.4 and likely A.5 of the Coding Guidelines.
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.
There is another PR fixing this. It does not need to be done in one go.
@@ -73,6 +73,9 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU") | |||
endif() | |||
zephyr_link_libraries(c) | |||
|
|||
# newlib needs this to expose the full Zephyr C Library API | |||
zephyr_compile_definitions(_POSIX_C_SOURCE=200809L) |
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.
Is it possible to use this instead? That would change the definition to a local one rather than a global one (which would conflict in many places).
zephyr_compile_definitions(_POSIX_C_SOURCE=200809L) | |
zephyr_library_compile_definitions(_POSIX_C_SOURCE=200809L) |
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.
No, the whole point of this define is to ensure that newlib exposes the Zephyr C API as defined by Rule A.4 in the Coding Guidelines. Unless and until newlib itself is fixed to provide Zephyr compatibility, we can either
- Abandon Rule A.4 and assert that Zephyr only uses ISO C interfaces
- Define
_POSIX_C_SOURCE=200809L
globally - Find some alternative mechanism to get newlib to expose the extended functions.
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.
@keith-packard would it be an option to only expose by default the ISO C interface, but still allow those extra functions defined in Rule A.4 (thru individual waives in PRs that need to use them, where setting the _POSIX_C_SOURCE macro is allowed in particular cases). Effectively what you described here: #67040 (comment)
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.
Are you saying that we require applications define _POSIX_C_SOURCE=200809L
to gain access to the extended functions? Because if it's not required, then we're adding implicit dependencies on using only a C library with Zephyr compatibility (picolibc or the minimal C library).
That would certainly be easier for C library developers, but it seems like it will require careful auditing of changes in any file with such a definition to ensure that it doesn't accidentally start depending on additional POSIX functionality.
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.
Are you saying that we require ..
Yes
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.
It seems like that would also require allowing core Zephyr files to contain such definitions; have tooling that prevents valid code from being merged will slow down development. Because once the definition is present in a source file, no future changes to that file will see the same review, hence allowing non-approved functions to leak in. Alternatively, more sophisticated tooling that detected the use of POSIX functions beyond the approved list.
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.
You are right that in general that would be the case, and that would be very far from ideal.
Though today a quick check seems to show:
- there is nothing in the "zephyr kernel" using
strnlen()
(the only exception in A.4). - for more peripheral code in the tree, there is a few uses of
strnlen()
andstrtok_r()
(rule A.5 exceptions).
But given that today, at least for the tests we are running, all those built with just this
123bdfb
I wonder if it would be best to, by now, postpone this particular point (I would very much like to have @stephanosio on this discussion), and not do this particular line change (or that other commit) in this PR; The rest of the PR seems fully uncontroversial and an overall improvement.
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.
We can't remove instances of #define _POSIX_C_SOURCE
in most places without somehow dealing with newlib's lack of Zephyr support. Otherwise, building code with newlib that uses strnlen
will fail.
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.
It would still be slightly more ideal to remove application conformance macros from global cflags.
That requires that upstream newlib be fixed to provide Zephyr support. |
d7fd9ac
to
0ff2cd9
Compare
0ff2cd9
to
177b4f2
Compare
This steals @cfriedt 's idea to wrap string.h and add the non ISO-C declarations there, but is newlib specific and so doesn't risk breaking other C libaries. |
177b4f2
to
19a50f8
Compare
Hi @keith-packard , this PR now has a very different content and target than originally. That can be quite confusing for reviewers, as the previous comments and commits are unrelated. Moreover some may have already muted this PR, and the merge criteria does not properly account for PRs that morph. Setting the DNM label due to this. |
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 looks fine to me. Thanks @keith-packard
Or if you prefer to make a separate PR, sure. I have no issues with the current incantation though.
Not totally necessary, but FWIR there are some CI errors right now that this will fix, so it might be a good idea to file a bug report.
CI errors are priority: high
, so that will ensure it gets merged with the release (IIRC, we require zero high priority issues with a release).
19a50f8
to
d7fd9ac
Compare
I've reset this PR back to the state before it became just patches for newlib compatibility. It's no longer relevant for anything but historical purposes. |
Picolibc now has explicit Zephyr support so we no longer need _POSIX_C_SOURCE defined to get the complete Zephyr C Library API