This reflects whether newlib is available in the environment. This
symbol should be used in place of TOOLCHAIN_HAS_NEWLIB.
Signed-off-by: Keith Packard <keithp@keithp.com>
Add a prompt to the Kconfig symbol so that applications can select this in
their configuration to guide C library selection away from the minimal C
library.
Signed-off-by: Keith Packard <keithp@keithp.com>
This will (eventually) permit use of a common malloc implementation with
other C libraries, reducing the amount of Zephyr-specific code required
to support each C library.
Signed-off-by: Keith Packard <keithp@keithp.com>
This allows the C library common library to be empty if no pieces are
needed, eliminating cmake warnings.
Signed-off-by: Keith Packard <keithp@keithp.com>
Add a prompt to the Kconfig symbol so that applications can select this in
to guide C++ standard library selection towards configurations which
provide a complete implementation.
Signed-off-by: Keith Packard <keithp@keithp.com>
Add limits.h header that defines PATH_MAX as this is not defined
by the toolchain headers.
The value of 256 for PATH_MAX is based on how it is set in
lib/libc/minimal/include/limits.h.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
This ensures that the compiler won't end up recognizing patterns in code
that map to known built-in functions, like noticing that the memcpy
implementation looks a lot like a memory copy operation that could be
replaced by a call to ... memcpy.
When built with -ffreestanding, this has no effect as that option always
enables -fno-builtin.
Signed-off-by: Keith Packard <keithp@keithp.com>
When gcc is building without -fno-builtin, it will optimize calls like
printf("\n") into a call to putchar('\n'), but it won't use a static inline
in that case, instead insisting on a real function.
To make this a bit easier, adopt the usual C library practice of making
putc and putchar macros instead of static inline functions. There's no loss
of typechecking as the parameters are directly passed to underlying
functions with the same parameter types.
Signed-off-by: Keith Packard <keithp@keithp.com>
Remove statement probably left after rebase. ret should be 0 or
error codes, described in docs, and it is rewritten 4 lines below.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
In d540cf8877 I tried to optionally enable the cache management
functions in Open-AMP introducing a new CONFIG_OPENAMP_WITH_DCACHE
symbol.
This is not working. Introduce a proper fix to have this actually
working correctly as intended.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
When using the toolchain C library, that must be added to the link command
after all other libraries and modules in the system to resolve undefined
symbols.
Signed-off-by: Keith Packard <keithp@keithp.com>
Add an explicit compiler configuration, COMPILER_FREESTANDING, which
controls whether the compiler should operate in freestanding or hosted mode
(according to the C and C++ language specifications.
This depends on having a C library which conforms with the language
specification, and the minimal C library does not. Have the minimal C
library select COMPILER_FREESTANDING to continue using freestanding mode
with that library.
For other C libraries, leave this disabled by default while allowing users
to enable it if they want to go back to the previous configuration.
Signed-off-by: Keith Packard <keithp@keithp.com>
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Add string.h header that declerates prototype for strnlen()
as this is not provided by the toolchain headers.
Add strings.h to allow anything that expects strncasecmp() to
be defined there to build correctly. The arm toolchain actually
defines strncasecmp() in <string.h> so we just have <strings.h>
include <string.h>.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
* Move 'struct _timespec' into sys/_timespec.h as expected by
<posix/time.h>.
* Introduce 'struct timeval' in sys/_timeval.h as expected by
<posix/time.h>.
* Add mode_t to <sys/types.h> as expected by <posix/stat.h>
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Various headers include <sys/cdefs.h> like zephyr/posix/sys/stat.h.
When building with the arm-clang toolchain we utilize armstdc
so we need an empty cdefs.h similar to what minimal libc has so
things will build.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
We get compile warnings of the form:
error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
[-Werror,-Wint-in-bool-context]
if (!isprint(byte)) {
^
Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
We get compile warnings of the form:
error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
[-Werror,-Wint-in-bool-context]
if (!isprint(byte)) {
^
Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Introduce a place to share implementations of libc functions that
are needed by different libc versions. Place time() in this common
location so it can be shared when building for either minimal libc or
armclang libc.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
* add opening and closing braces around several blocks
* convert dos line endings to unix
* move assignments out of conditionals
* ensure adequate spacing after control blocks
Signed-off-by: Chris Friedt <cfriedt@meta.com>
* Add a flexible Hashmap API
* Add a Separate-Chaining Hashmap Implementation
* Add a Open-Addressing Linear Probe Hashmap Implementation
* Add a C-Wrapper for `std::unordered_map` for benchmarking
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Changed incrementing `for` loop counters to `size_t` from `int` to
eliminate warning, "warning: comparison of integer expressions of
different signedness: 'uint32_t' {aka 'unsigned int'} and 'int'
[-Wsign-compare]"
Signed-off-by: Zachary J. Fields <zachary_fields@yahoo.com>
Changed incrementing `for` loop counters to `size_t` from `int` to
eliminate warning, "warning: comparison of integer expressions of
different signedness: 'uint32_t' {aka 'unsigned int'} and 'int'
[-Wsign-compare]"
Signed-off-by: Zachary J. Fields <zachary_fields@yahoo.com>
Disable tests/kernel/mem_protect/syscalls for qemu_arc_em where
we trigger ARC QEMU bug which cause illegal instruction exception
on perfectly valid ARC code.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
This is a workaround for a compiler bug on (at least) GCC 12.1.0 in
Zephyr SDK 0.15.1. The optimizer generates this function with a last
instruction that is an unconditional branch (a tail call into the
chunk_set() handling). But that means that the NEXT instruction gets
decoded as part of the branch delay slot, but that instruction isn't
part of this function! Some instructions aren't legal in branch delay
slots. One of those is ENTER_S, which is a very common entry
instruction for whatever function the linker places after us. It
seems like the compiler doesn't understand this problem. Stuff a NOP
in to guarantee the code is legal.
Comment above is duplicated in the code. The workaround is
straightforward once the issue is understood, but the path to get here
was hilariously weird.
Fixes#54720
Signed-off-by: Andy Ross <andyross@google.com>
Clang support still work in progress in zephyr. So for now enable only
on gcc based toolchains.
We should enable this back for more toolchains once we have full clang
support and are able to verify.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
With all of the test suite issues on this board fixed, qemu_x86_tiny should
now be usable with picolibc.
Signed-off-by: Keith Packard <keithp@keithp.com>
Picolibc now supports all of the Zephyr SDK target architectures for C.
qemu_x86_tiny needs fixes to get the libc partition linked
into the right spot. See issue #54148
Signed-off-by: Keith Packard <keithp@keithp.com>
The limiting factor is the output bitmask that says which elements have
been filled in by the parser. This patch changes the bitmask type from int
to int64_t.
Signed-off-by: Björn Stenberg <bjorn@haxx.se>
Although the eventfd API is not (yet) a part of POSIX,
it's pretty well ubiquitous on POSIX systems now.
Enable it by default when `CONFIG_POSIX_API=y`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The `getopt()` function is part of POSIX and should be
available when applications choose to enable general POSIX
API support.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
With the `<zephyr/posix/...> prefix, it became
exponentially more difficult to integrate 3rd-party
libraries that depend on the POSIX API.
Standard POSIX headers should be available in standard
include paths - and that should most certainly the case
when `CONFIG_POSIX_API=y`.
With this change:
* When `CONFIG_POSIX_API=y`
- applications have explicitly chosen to use
POSIX APIs.
- all standard POSIX includes are in the default
include path.
* When `CONFIG_POSIX_API=n`
- applications *may* include POSIX headers
explicitly with the namespaced prefix
- e.g. `#include <zephyr/posix/unistd.h>`
- individual Kconfig options can be used to
enable POSIX features selectively, such as
`getopt` or `eventfd`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Refactor sys_clock_disable not implemented behavior.
This follows the coding guidelines
Rule A.1: Conditional Compilation:
Do not conditionally compile function declarations in header files.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
libstdc++ is supported with Picolibc only when the toolchain version of
Picolibc is use -- libstdc++ must be built using a specific Picolibc build
and libstdc++ is included with the toolchain.
Ideally, we'd allow the use of the Picolibc module whenever we weren't
using the GNU libstdc++, including when using the minimal libc++. However,
the obvious dependency settings create a loop:
config PICOLIBC
depends on PICOLIBC_SUPPORTED
config PICOLIBC_SUPPORTED
depends on !(GLIBCXX_LIBCPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr")
config GLIBCXX_LIBCPP
depends on NEWLIB_LIBC || PICOLIBC
To break this loop, we replace GLIBCXX_LIBCPP in the second block with
CPP:
config PICOLIBC_SUPPORTED
depends on !(CPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr")
This means that picolibc cannot be used with any C++ apps when using the
Zephyr SDK, even when not using the GNU libstdc++. However, Zephyr SDK 0.16
will come with an additional Kconfig file that includes:
config PICOLIBC_SUPPORTED
def_bool y
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr"
This will override the Kconfig bits included in Zephyr and allow use of the
Picolibc module with C++ code, including using the minimal libc++ bits.
Signed-off-by: Keith Packard <keithp@keithp.com>
This ensures that all pending writes are committed. This is relevant for
flags in .noinit SRAM that are read back after reset.
Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
This commit reworks the C++ standard library configurations such that:
* the separation between the Zephyr minimal C++ library and the fully
featured C++ standard libraries, such as GNU libstdc++, is clear.
This is done by deprecating the Kconfig `CONFIG_LIB_CPLUSPLUS`
symbol, which implies that the minimal C++ library is selected when
set to `n`, and introducing the `CONFIG_MINIMAL_LIBCPP` symbol.
* the type of the selected C++ standard library is clear. This is done
by introducing a Kconfig choice, `LIBCPP_IMPLEMENTATION`, for the C++
standard library type and providing the choice symbols for each
library type supported, such as `CONFIG_MINIMAL_LIBCPP` and
`CONFIG_GLIBCXX_LIBCPP`.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
The Kconfig `CONFIG_RTTI` symbol enables the C++ Run-Time Type
Information (RTTI) support and is a feature of the standard C++
library; therefore, it should be prefixed with `CPP_` as with the rest
of the C++-specific symbols.
This commit renames the Kconfig `CONFIG_RTTI` symbol to
`CONFIG_CPP_RTTI` in order to better align with the other existing C++
Kconfig symbols, and deprecates the old `CONFIG_RTTI` symbol.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>