Skip to content

Commit c039bed

Browse files
committed
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 zephyrproject-rtos#14310 Signed-off-by: Kumar Gala <[email protected]>
1 parent 269935d commit c039bed

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ endif()
348348

349349
zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage)
350350

351-
zephyr_system_include_directories(${NOSTDINC})
352-
353351
# Force an error when things like SYS_INIT(foo, ...) occur with a missing header.
354352
zephyr_cc_option(-Werror=implicit-int)
355353

cmake/compiler/gcc/target_baremetal.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ macro(toolchain_cc_nostdinc)
55
NOT COMPILER STREQUAL "xcc" AND
66
NOT CONFIG_NATIVE_APPLICATION)
77
zephyr_compile_options( -nostdinc)
8+
zephyr_system_include_directories(${NOSTDINC})
89
endif()
910

1011
endmacro()

lib/libc/newlib/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ zephyr_library_sources(libc-hooks.c)
77
# unable to, it will be up to the user to specify LIBC_*_DIR vars to
88
# point to a newlib implementation.
99

10+
# We need to make sure this is included before the standard system
11+
# header include path's since we build with -ffreestanding and need
12+
# our libc headers to be picked instead of the toolchain's ffreestanding
13+
# headers.
1014
if(LIBC_INCLUDE_DIR)
11-
zephyr_include_directories(${LIBC_INCLUDE_DIR})
15+
zephyr_system_include_directories(${LIBC_INCLUDE_DIR})
1216
endif()
1317

1418
if(LIBC_LIBRARY_DIR)

0 commit comments

Comments
 (0)