Skip to content
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

Several fixes around POSIX_SOURCE, remove global definitions of POSIX_SOURCE #67052

Merged
merged 20 commits into from
Jan 26, 2024

Conversation

aescolar
Copy link
Member

@aescolar aescolar commented Dec 28, 2023

Some cleanup around the selection of the API provided by the C library.
The main idea is to limit where the SOURCE selection is applied to much fewer files than before.

This PR includes some commits from #67040 so as to provide a complete solution. But it only includes those commits that are inline with the overall direction of this PR of removing all global definitions of these macros.

Background on the PR strategy differences:
Currently #67040 cleans up only the global definitions done by picolibc, but sets newlibc to define those globally.
The current assumption in 67040 is that all functions listed in the coding guidelines rules A.4 and A.5 should be globally available, without needing to set any macro by the user file, even that some of those functions are not part of the C std library API but extensions. Unfortunately, this sets a requirement on the libC integration to ensure they are exposed. See #67040 (comment).

Instead, this PR solves the global use of POSIX_SOURCE issue, while postponing deciding on and solving the libC integration topic ( #67040 (comment) )


Notes about the checkpatch warnings:

Sidenote: We can avoid all those check-patch warnings by defining these macros in cmake, but it does not feel nice to do so, just because of checkpatch.


Fixes #66921

@aescolar aescolar force-pushed the POSIX_SOURCE branch 3 times, most recently from b8c9623 to efaaef3 Compare December 28, 2023 17:14
Copy link
Collaborator

@keith-packard keith-packard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ssize_t -> int changes are unrelated and also seem wrong? I'd also remove the #undef bits; they shouldn't be necessary once we get rid of the global definitions

@@ -7,6 +7,20 @@

#define DT_DRV_COMPAT zephyr_sim_eeprom

#ifdef CONFIG_ARCH_POSIX
#undef _POSIX_C_SOURCE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the undef here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a harmless safety.
A user may define this globally, another library may due to legacy or by mistake.
It is safe to undef macros even if they were never defined.
Given that we are here due to conflicts in this area, and that some feel strongly about defining this kind of macro globally, and that Zephyr as an OS is built quite monotonically with the app it seemed reasonable to play safe.
Wouldn't you want to add them on your PR? :)

@bjarki-andreasen bjarki-andreasen self-requested a review December 29, 2023 10:31
Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the changes :)

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary nak until the issue described in #67181 can be brought to the AWG.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Jan 24, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-picolibc and removed DNM This PR should not be merged (Do Not Merge) labels Jan 24, 2024
@aescolar aescolar changed the title Several fixes around POSIX_SOURCE Several fixes around POSIX_SOURCE, remove global definitions of POSIX_SOURCE Jan 24, 2024
@aescolar aescolar marked this pull request as ready for review January 24, 2024 12:32
@zephyrbot zephyrbot requested a review from dcpleung January 24, 2024 12:33
aescolar and others added 8 commits January 25, 2024 16:29
strnlen() and strtok_r() are tested in this files
which are extensions to the the
std C library. Let's explicity select one of the extensions
also when building with the host C library,
instead of relaying on somebody having
set it for this file somewhere else.

Also, let's be nice and undefine them first in case they had
been defined somewhere else in the build scripts.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
This test uses functions which are extensions to
the C library. Let's explicity select one of the extensions
which includes it instead of relaying on somebody having
set it for this file somewhere else.
(Note this test is exclusive to native targets)

Signed-off-by: Alberto Escolar Piedras <[email protected]>
strnlen is not a C standard API, but an extension.
Instead of relaying that the SOURCE macro was set somewhere else
of that the C library provides a prototype anyhow
let's explicitly define it for this library.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
strnlen is not a C standard API, but an extension.
Instead of relaying that the SOURCE macro was set somewhere else
of that the C library provides a prototype anyhow
let's explicitly define it for this library.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
This test uses functions and types which are extensions to
the C library. Let's explicity select one of the extensions
which includes it instead of relaying on somebody having
set it for this file somewhere else.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
Instead of relaying on those macros having been defined
somewhere else let's define them for this file.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
This was necessary to get Picolibc to expose the whole Zephyr C library
API, but current versions of the SDK use a version of Picolibc with
built-in Zephyr support.

Signed-off-by: Keith Packard <[email protected]>
Instead of relaying on those macros having been defined
somewhere else let's define them for this library.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
@henrikbrixandersen
Copy link
Member

henrikbrixandersen commented Jan 25, 2024

The compliance check failures are false positives.

The srandom function is not available
unless _XOPEN_SOURCE is set > 500 or an equivalent
declaration is done.
Let's set it.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
Do not define these macros globally, but instead
define them only for this library and when needed.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
Both zcbor_encode.c & zcbor_decode.c use strnlen()
In general these 2 functions are only exposed by the C library
if _POSIX_C_SOURCE is set 200809L.
But neither of these files (or their build scripts), are setting
this macro, causing build warnings
 Implicit declaration of function ‘strnlen’
which turn into failures in CI with some libCs.
Let's set this macro to avoid this issue.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK. Thanks!

Copy link
Contributor

@rlubos rlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Net part looks ok

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks @aescolar 👍

@nashif nashif merged commit 1b90d29 into zephyrproject-rtos:main Jan 26, 2024
45 of 46 checks passed
@aescolar aescolar deleted the POSIX_SOURCE branch January 26, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arch: posix: _POSIX_C_SOURCE declaration conflicts with the rest of the system
10 participants