From c039bed61701cd95efd20fcefcab316e408154dd Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Tue, 12 Mar 2019 10:22:48 -0500 Subject: [PATCH] libc: newlib: Cleanup/fix setting of system include paths When we build with newlib we don't set -nostdinc. In that case make sure that we leave it to the toolchain to set the system include paths. The one exception to leaving to the toolchain to set the system include paths is the path to the newlib headers. Since we build with -ffreestanding we need to make sure the newlib header path is the before the toolchain headers. Otherwise the toolchain's 'freestanding' headers get picked up and that causes issues (for example getting PRI*64 defined properly from inttypes.h due to __STDC_HOSTED__ being '0'). For newlib we accomplish this by having the only system header specified by zephyr_system_include_directories() being just the newlib headers. Note: for minlibc we leave things alone as things just happen to work as the -I include of the libc headers takes precedence over -isystem so we get the libc headers over the toolchain ones. For the newlib case it appears that setting both -I and -isystem for the same dir causes the -I to be ignored. Fixes #14310 Signed-off-by: Kumar Gala --- CMakeLists.txt | 2 -- cmake/compiler/gcc/target_baremetal.cmake | 1 + lib/libc/newlib/CMakeLists.txt | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2170567d3df51..c5c9739ccd878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,8 +348,6 @@ endif() zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) -zephyr_system_include_directories(${NOSTDINC}) - # Force an error when things like SYS_INIT(foo, ...) occur with a missing header. zephyr_cc_option(-Werror=implicit-int) diff --git a/cmake/compiler/gcc/target_baremetal.cmake b/cmake/compiler/gcc/target_baremetal.cmake index dcd8c852f12a0..0ed28e6f89530 100644 --- a/cmake/compiler/gcc/target_baremetal.cmake +++ b/cmake/compiler/gcc/target_baremetal.cmake @@ -5,6 +5,7 @@ macro(toolchain_cc_nostdinc) NOT COMPILER STREQUAL "xcc" AND NOT CONFIG_NATIVE_APPLICATION) zephyr_compile_options( -nostdinc) + zephyr_system_include_directories(${NOSTDINC}) endif() endmacro() diff --git a/lib/libc/newlib/CMakeLists.txt b/lib/libc/newlib/CMakeLists.txt index fd13e7ebc018f..d97e3a38f96b5 100644 --- a/lib/libc/newlib/CMakeLists.txt +++ b/lib/libc/newlib/CMakeLists.txt @@ -7,8 +7,12 @@ zephyr_library_sources(libc-hooks.c) # unable to, it will be up to the user to specify LIBC_*_DIR vars to # point to a newlib implementation. +# 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_include_directories(${LIBC_INCLUDE_DIR}) + zephyr_system_include_directories(${LIBC_INCLUDE_DIR}) endif() if(LIBC_LIBRARY_DIR)