Description
newlib.h
is responsible for defining the newlib build configurations so that the newlib headers can expose only the enabled features to the application code, and the nano.specs
is responsible for configuring the include and library paths for the nano build of the newlib.
When --specs=nano.specs
is specified to GCC, the newlib nano (libc_nano.a
) is linked instead of the full newlib (libc.a
) and the include/newlib-nano
directory, which contains the newlib.h
specific to the newlib nano build, is added as a system include directory, such that the nano newlib.h
is included by application code instead of the full newlib.h
, which resides in include
.
The nano.specs
file currently specifies the newlib.h
include path as follows:
*cpp_unique_options:
-isystem =/include/newlib-nano %(nano_cpp_unique_options)
This is incorrect -- the =
at the beginning of the include path is effectively no-op and GCC tries to literally resolve the path as =/include/newlib-nano
, which obviously is not a valid path, and this leads to this include path being ignored and the newlib.h
for the full newlib build from include/
being included by the application code:
$ echo | /opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc --specs=nano.specs -E -Wp,-v -
ignoring nonexistent directory "=/include/newlib-nano"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/include"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/sys-include"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/sys-include
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
This can be corrected as follows so that the include/newlib-nano
path is resolved based on the GCC_EXEC_PREFIX
:
--- nano.specs
+++ nano.specs
@@ -3,7 +3,7 @@
%rename cpp_unique_options nano_cpp_unique_options
*cpp_unique_options:
--isystem =/include/newlib-nano %(nano_cpp_unique_options)
+-isystem %:getenv(GCC_EXEC_PREFIX ../../arm-zephyr-eabi/include/newlib-nano) %(nano_cpp_unique_options)
*nano_libc:
-lc_nano
After applying the patch above, the include paths are as follows, which are correct:
$ echo | /opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc --specs=nano.specs -E -Wp,-v -
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/include"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/sys-include"
ignoring duplicate directory "/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/../../arm-zephyr-eabi/include/newlib-nano
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/sys-include
/opt/zephyr-sdk-0.14.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"