lib/newlib: revert treatment of libc files as system includes
The solution from #14312 of using -isystem to prioritize the position of the libc directory bypasses the effect of -ffreestanding with respect to libc symbols expected to be present in a non-hosted environment. Further, it breaks C++ with the ARM Embedded toolchain as the system fails to find the right file with #include_next. Use a more fine-grained solution that explicitly includes the underlying newlib header required for <inttypes.h> support before moving on to include the next available one, whether system or non-system. Closes #17564 Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
bd72ea1df9
commit
96c1b05125
|
@ -3,18 +3,23 @@
|
|||
zephyr_library()
|
||||
zephyr_library_sources(libc-hooks.c)
|
||||
|
||||
# Zephyr normally uses -ffreestanding, which with current GNU toolchains
|
||||
# means that the flag macros used by newlib 3.x <inttypes.h> to signal
|
||||
# support for PRI.64 macros are not present. To make them available we
|
||||
# need to hook into the include path before the system files and
|
||||
# explicitly include the newlib header that provides those macros.
|
||||
zephyr_include_directories(include)
|
||||
|
||||
# LIBC_*_DIR may or may not have been set by the toolchain. E.g. when
|
||||
# using ZEPHYR_TOOLCHAIN_VARIANT=cross-compile it will be either up to the
|
||||
# toolchain to know where it's libc implementation is, or if it is
|
||||
# unable to, it will be up to the user to specify LIBC_*_DIR vars to
|
||||
# point to a newlib implementation.
|
||||
# point to a newlib implementation. Note that this does not change the
|
||||
# directory order if LIBC_INCLUDE_DIR is already a system header
|
||||
# directory.
|
||||
|
||||
# We need to make sure this is included before the standard system
|
||||
# header include path's since we build with -ffreestanding and need
|
||||
# our libc headers to be picked instead of the toolchain's ffreestanding
|
||||
# headers.
|
||||
if(LIBC_INCLUDE_DIR)
|
||||
zephyr_system_include_directories(${LIBC_INCLUDE_DIR})
|
||||
zephyr_include_directories(${LIBC_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
if(LIBC_LIBRARY_DIR)
|
||||
|
|
30
lib/libc/newlib/include/stdint.h
Normal file
30
lib/libc/newlib/include/stdint.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_STDINT_H_
|
||||
#define ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_STDINT_H_
|
||||
|
||||
/* Work around -ffreestanding absence of defines required to support
|
||||
* PRI.64 macros in <inttypes.h> by including the newlib header that
|
||||
* provides the flag macros.
|
||||
*/
|
||||
|
||||
#include <newlib.h>
|
||||
|
||||
#ifdef __NEWLIB__
|
||||
/* Has this header. Older versions do it in <stdint.h>. */
|
||||
#include <sys/_stdint.h>
|
||||
#endif /* __NEWLIB__ */
|
||||
|
||||
/* This should work on GCC and clang.
|
||||
*
|
||||
* If we need to support a toolchain without #include_next the CMake
|
||||
* infrastructure should be used to identify it and provide an
|
||||
* alternative solution.
|
||||
*/
|
||||
#include_next <stdint.h>
|
||||
|
||||
#endif /* ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_STDINT_H_ */
|
Loading…
Reference in a new issue