-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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: newlib/picolibc: define prototypes for non-ansi C functions #57619
Conversation
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.
If you want GNU functions in you application, then define _GNU_SOURCE in your application. That's a well defined mechanism for getting libc extensions into your namespace.
Same issue as the I only see this as a temporary workaround until we add the support for properly filtering the extensions allowed by Zephyr using something like |
I'm definitely not suggesting setting _GNU_SOURCE in any global header, just in specific source code (not core Zephyr) which want to use GNU extensions. That will effectively label exceptions to the Zephyr policy.
I'd suggest that things happen in the other order -- we map |
|
For example setting I think this is the cleanest approach at this point. |
It looks like |
@galak Guess what ... zephyr/tests/lib/mem_alloc/src/main.c Line 27 in b004224
p.s. Another reason to avoid requiring people to define their own |
I agree that apps shouldn't have to define various Being able to test that the application respects the API it has requested is a separable issue, and one which can only be achieved by getting |
As per the proposed coding guidelines in #57598, the idea is to not allow the upstream codebase to use the C library extensions that are not explicitly allowed by the coding guidelines; and for the allowed extensions, a specific (de-facto) standard will be designated (e.g. POSIX for Of course, downstream users and applications are not obligated to follow this and may choose to define One way we could prevent that is by adding the feature test macro ifdefs to replicate exactly what each libc does (just copy and paste the block of code defining the function from the original libc header) -- while it is not a pretty solution, it will keep the Zephyr codebase more clean overall by not requiring each source file to define the feature test macros like |
lib/libc/newlib/include/stdint.h
Outdated
void qsort_r(void *base, size_t nmemb, size_t size, | ||
int (*compar)(const void *, const void *, void *), void *arg); |
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.
As per #57619 (comment), in order to support downstream applications that may choose to pull in a different flavour (e.g. BSD) of this function, it may be desirable to pull in the full definition here:
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 think we should cross that bridge if/when someone wants to do that.
Ok, this is getting messy -- It sounds like you want the system, when not directed with some Maybe I just need to understand the desired end point. I think an explicit goal should be that code which defines As to the process, I'd much rather the underlying root problems get fixed than layer kludges on top. Maybe newlib would be just fine taking |
Yes; at least, based on the status quo of the non-standard functions available in the minimal libc and have been used throughout the Zephyr codebase, which will likely end up in the list of "allowed" non-ISO functions.
Yes, that sounds like a fairly accurate description of what we want eventually.
For Newlib, there is not much of a rush and it will certainly be preferable if we upstream the Nevertheless, there remains the problem of maintaining compatibility with older versions of toolchains that do not include this patch (not just Zephyr SDK, but third-party toolchains such as GNU Arm Embedded). |
Here's an equivalent series for picolibc. Note that this currently requires that Zephyr explicitly define https://github.com/zephyrproject-rtos/picolibc/tree/zephyr-source |
Would be good to default to the POSIX version of strerror_r when _ZEPHYR_SOURCE is defined. |
I was hoping @cfriedt would figure out if you wanted the POSIX or GNU version of this. I'll stick the POSIX version in this series and we can review. |
I've fixed this -- if you have |
I've added commits to pr #57340 which pulls in the picolibc Zephyr API changes from https://github.com/zephyrproject-rtos/picolibc/tree/zephyr-source, fix a couple of unneeded |
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.
A couple of copy-paste typos by the looks of it
I think we should pull the picolibc changes out of this series and see if we can land the upstream fixes instead. We should be able to get those fixes back-ported to current picolibc bits used in the SDK and module to avoid introducing other picolibc changes into the environment. |
The issue is we need the picolibc changes for older SDKs that wouldn't have the new picolibc changes. |
Define prototypes for qsort_r, strnlen, strtok_r, and strerror_r as these are not part of the standard ANSI defined C-lib. As newlib & picolibc provided both the GNU and POSIX style of strerror_r we have to redefine strerror_r to __xpg_strerror_r to get the POSIX version. Signed-off-by: Kumar Gala <[email protected]>
This should now be defined in strings.h for newlib and picolibc so don't need to define it here. Signed-off-by: Kumar Gala <[email protected]>
#endif | ||
|
||
size_t strnlen(const char *, size_t); | ||
char *strtok_r(char *, const char *, char **); |
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.
Does the compiler complain when you add identifier names here and the application has defined _POSIX_C_SOURCE
so that newlib also declares these functions? If not, adding them to make the compliance checks pass would be nice (the names serve as a limited form of documentation if chosen well).
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 would like to add feature test macros soon on the POSIX side too, so it's good to be aware that it's in the pipes
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.
Please test with _POSIX_C_SOURCE
(and _GNU_SOURCE
?) defined in various ways to make sure these don't conflict with the newlib definitions. I'd actually encourage you to create per-function tests using those so we can catch mis-matching prototypes. I was concerned about that aspect of this patch, but with tests like that, we'll be safe.
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
dev-review: @galak - will you be moving forward with this one? If not, it might make sense to close |
In particular, the picolibc changes to expose the Zephyr API when |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
No description provided.