-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Description
Describe the bug
Newlib does a good job of being mostly posix conformant. I noticed that there were some inconsistencies though when implementing dirent.h functionality.
Namely, Newlib (at least Zephyr's fork) does not define the mandatory constant minimum values _POSIX_NAME_MAX and _XOPEN_NAME_MAX among many others.
Initially, I assumed that the Newlib C library did include many of the mandatory POSIX limit definitions, but that seems to not be the case today.
target platform: all
workaround: linked pr
Regression
- This is a regression.
Steps to reproduce
Apply the following diff to samples/hello_world.
diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c
index c550ab461cb..df844b87e29 100644
--- a/samples/hello_world/src/main.c
+++ b/samples/hello_world/src/main.c
@@ -4,8 +4,31 @@
* SPDX-License-Identifier: Apache-2.0
*/
+#define _POSIX_C_SOURCE 200809L
+#define _XOPEN_SOURCE 700
+
+#include <limits.h>
#include <stdio.h>
+#include <zephyr/toolchain.h>
+
+#if !(defined(_POSIX_RE_DUP_MAX) || defined(_POSIX2_RE_DUP_MAX))
+/* there are in fact a number of mandatory macros missing from Newlib, not just those below. This one just happens to exist */
+#error "_POSIX_RE_DUP_MAX not defined: this implies the expected behaviour of limits.h is incorrect"
+#endif
+
+#ifndef _POSIX_NAME_MAX
+#error "_POSIX_NAME_MAX not defined"
+#else
+BUILD_ASSERT(_POSIX_NAME_MAX == 14, "non-conformant value of _POSIX_NAME_MAX");
+#endif
+
+#ifndef _XOPEN_NAME_MAX
+#error "_XOPEN_NAME_MAX not defined"
+#else
+BUILD_ASSERT(_XOPEN_NAME_MAX == 255, "non-conformant value of _XOPEN_NAME_MAX");
+#endif
+
int main(void)
{
printf("Hello World! %s\n", CONFIG_BOARD_TARGET);Build against picolibc (successful)
west build -p -b qemu_riscv64 samples/hello_worldBuild for newlib (fails)
west build -p -b qemu_riscv64 samples/hello_world -- -DCONFIG_NEWLIB_LIBC=yRelevant log output
/Users/cfriedt/zephyrproject/zephyr/samples/hello_world/src/main.c:16:2: error: #error "_POSIX_NAME_MAX not defined"
16 | #error "_POSIX_NAME_MAX not defined"
| ^~~~~
/Users/cfriedt/zephyrproject/zephyr/samples/hello_world/src/main.c:22:2: error: #error "_XOPEN_NAME_MAX not defined"
22 | #error "_XOPEN_NAME_MAX not defined"
| ^~~~~
[13/79] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/cbprintf_complete.c.obj
ninja: build stopped: subcommand failed.Impact
Major – Severely degrades functionality; workaround is difficult or unavailable.
Environment
OS: Ubuntu
SDK: 0.17.2
Commit: f5cc5d8
Additional Context
Mentioned here #93387 (comment) and here #94612 (comment)
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html