Skip to content

Conversation

@stephanosio
Copy link
Contributor

@stephanosio stephanosio commented Dec 2, 2019

This PR includes a series of commits required to support building the 'nano' variant of C/C++ runtime libraries (using newlib; other libc support can be added in the future using a similar method).

The 'nano' runtime libraries are specified by the nano.specs file and are often included in embedded toolchains (e.g. GNU ARM Embedded) for memory-constrained target devices.

The following is a brief summary of the changes introduced by this PR:

  1. Add nano variant-specific newlib configurations in config/libc/newlib.in.

    • Keep all LIBC_NEWLIB_... configs as is. These configurations will be used to build the normal variant (lib{c,g}.a).
    • Mirror all LIBC_NEWLIB_... configs to LIBC_NANO_NEWLIB_... configs. These configurations will be used to build the nano variant (lib{c,g}_nano.a).
  2. Modify newlib build script to build LIBC and LIBC_NANO variants separately.

  3. Build an additional libstdc++ with -Os (optimise for size) and place it as lib{std,sup}c++_nano.a (the default libstdc++ is built with -O2).

  4. Strip debug information from the built libraries.

Refer to the following issues for the rationale of supporting both normal (non-nano) and nano variants: zephyrproject-rtos/sdk-ng#151

This PR supersedes #1225, which only renames the default runtime libraries to comply with nano.specs without actually building a separate nano variant.

@stephanosio
Copy link
Contributor Author

NOTE: The following must be set in order to build the 'nano' runtime libraries:

  • newlib as libc nano: CT_LIBC_NANO_NEWLIB=y and (optionally) CT_LIBC_NANO_NEWLIB_... configs.
  • gcc libstdc++-v3 as libstdc++ nano: CT_CC_GCC_LIBSTDCXX_NANO=y

@stephanosio
Copy link
Contributor Author

stephanosio commented Dec 2, 2019

stephanos@DOMINUS:~$ ls -l ~/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib
total 16284
-rw-r--r--  1 stephanos stephanos     557 Dec  2 12:36 aprofile-validation.specs
-rw-r--r--  1 stephanos stephanos     573 Dec  2 12:36 aprofile-validation-v2m.specs
-rw-r--r--  1 stephanos stephanos     539 Dec  2 12:36 aprofile-ve.specs
-rw-r--r--  1 stephanos stephanos     555 Dec  2 12:36 aprofile-ve-v2m.specs
drwxrwxr-x  3 stephanos stephanos    4096 Dec  2 12:36 arm
drwxrwxr-x  2 stephanos stephanos    4096 Dec  2 13:37 cpu-init
-rw-r--r--  1 stephanos stephanos    1568 Dec  2 13:37 crt0.o
-rw-r--r--  1 stephanos stephanos     195 Dec  2 12:36 iq80310.specs
-rw-r--r--  2 stephanos stephanos 1098130 Dec  2 13:37 libc.a
-rw-r--r--  1 stephanos stephanos  943708 Dec  2 13:37 libc_nano.a
-rw-r--r--  2 stephanos stephanos 1098130 Dec  2 13:37 libg.a
-rw-r--r--  1 stephanos stephanos    7596 Dec  2 13:37 libgloss-linux.a
-rw-r--r--  1 stephanos stephanos  943708 Dec  2 13:37 libg_nano.a
-rw-r--r--  1 stephanos stephanos  655790 Dec  2 13:37 libm.a
-rw-r--r--  1 stephanos stephanos   24088 Dec  2 13:37 libnosys.a
-rw-r--r--  1 stephanos stephanos   14786 Dec  2 13:37 librdimon.a
-rw-r--r--  1 stephanos stephanos   14854 Dec  2 13:37 librdimon_nano.a
-rw-r--r--  1 stephanos stephanos   14786 Dec  2 13:37 librdimon-v2m.a
-rw-r--r--  1 stephanos stephanos   11064 Dec  2 13:37 librdpmon.a
-rw-r--r--  1 stephanos stephanos 5638604 Dec  2 13:37 libstdc++.a
-rw-r--r--  1 stephanos stephanos    2462 Dec  2 13:10 libstdc++.a-gdb.py
-rw-r--r--  1 stephanos stephanos 5439302 Dec  2 13:37 libstdc++_nano.a
-rw-r--r--  1 stephanos stephanos  329592 Dec  2 13:37 libsupc++.a
-rw-r--r--  1 stephanos stephanos  304524 Dec  2 13:37 libsupc++_nano.a
-rw-r--r--  1 stephanos stephanos     820 Dec  2 13:37 linux-crt0.o
-rw-r--r--  1 stephanos stephanos     121 Dec  2 12:36 linux.specs
-rw-r--r--  1 stephanos stephanos     740 Dec  2 12:36 nano.specs
-rw-r--r--  1 stephanos stephanos     277 Dec  2 12:36 nosys.specs
-rw-r--r--  1 stephanos stephanos     192 Dec  2 12:36 pid.specs
-rw-r--r--  1 stephanos stephanos    2192 Dec  2 13:37 rdimon-crt0.o
-rw-r--r--  1 stephanos stephanos    2192 Dec  2 13:37 rdimon-crt0-v2m.o
-rw-r--r--  1 stephanos stephanos     628 Dec  2 12:36 rdimon.specs
-rw-r--r--  1 stephanos stephanos     726 Dec  2 12:36 rdimon-v2m.specs
-rw-r--r--  1 stephanos stephanos    1476 Dec  2 13:37 rdpmon-crt0.o
-rw-r--r--  1 stephanos stephanos     147 Dec  2 12:36 rdpmon.specs
-rw-r--r--  1 stephanos stephanos    1060 Dec  2 13:37 redboot-crt0.o
-rw-r--r--  1 stephanos stephanos    6119 Dec  2 12:36 redboot.ld
-rw-r--r--  1 stephanos stephanos     192 Dec  2 12:36 redboot.specs
-rw-r--r--  1 stephanos stephanos    3392 Dec  2 13:37 redboot-syscalls.o
drwxrwxr-x 14 stephanos stephanos    4096 Dec  2 12:36 thumb
stephanos@DOMINUS:~$ find ~/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi -name *nano* -exec ls -l {} +
-rw-r--r-- 1 stephanos stephanos  916136 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/hard/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  916136 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/hard/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   14206 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/hard/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5233178 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/hard/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  299952 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/hard/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/hard/nano.specs
-rw-r--r-- 1 stephanos stephanos  916236 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/softfp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  916236 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/softfp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   14206 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/softfp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5233234 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/softfp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  299944 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/softfp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/arm/v5te/softfp/nano.specs
-rw-r--r-- 1 stephanos stephanos  943708 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  943708 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   14854 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5439302 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  304524 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/nano.specs
-rw-r--r-- 1 stephanos stephanos  855988 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  855988 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   13158 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5079190 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  280476 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/nofp/nano.specs
-rw-r--r-- 1 stephanos stephanos  851116 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v6-m/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  851116 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v6-m/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12852 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v6-m/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5059430 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v6-m/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  279356 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v6-m/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v6-m/nofp/nano.specs
-rw-r--r-- 1 stephanos stephanos  846828 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/hard/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  846828 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/hard/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12872 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/hard/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5054790 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/hard/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283880 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/hard/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/hard/nano.specs
-rw-r--r-- 1 stephanos stephanos  844532 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/softfp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  844532 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/softfp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12848 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/softfp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5054194 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/softfp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283632 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/softfp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+dp/softfp/nano.specs
-rw-r--r-- 1 stephanos stephanos  851512 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/hard/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  851512 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/hard/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12872 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/hard/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5057282 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/hard/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283888 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/hard/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/hard/nano.specs
-rw-r--r-- 1 stephanos stephanos  851140 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/softfp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  851140 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/softfp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12872 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/softfp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5057066 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/softfp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283880 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/softfp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m+fp/softfp/nano.specs
-rw-r--r-- 1 stephanos stephanos  848932 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  848932 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12828 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5051582 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  280456 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/nano.specs
-rw-r--r-- 1 stephanos stephanos  847596 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/hard/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  847596 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/hard/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12864 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/hard/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5055594 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/hard/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283676 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/hard/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/hard/nano.specs
-rw-r--r-- 1 stephanos stephanos  845284 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/softfp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  845284 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/softfp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12840 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/softfp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5054986 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/softfp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283428 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/softfp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7+fp/softfp/nano.specs
-rw-r--r-- 1 stephanos stephanos  848944 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7-m/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  848944 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7-m/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12828 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7-m/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5051602 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7-m/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  280472 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7-m/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7-m/nofp/nano.specs
-rw-r--r-- 1 stephanos stephanos  849636 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  849636 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12820 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5052042 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  280248 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7/nofp/nano.specs
-rw-r--r-- 1 stephanos stephanos  847884 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.base/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  847884 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.base/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12788 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.base/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5052126 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.base/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  279148 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.base/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.base/nofp/nano.specs
-rw-r--r-- 1 stephanos stephanos  849324 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/hard/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  849324 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/hard/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12900 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/hard/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5055358 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/hard/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  284048 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/hard/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/hard/nano.specs
-rw-r--r-- 1 stephanos stephanos  847016 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/softfp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  847016 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/softfp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12876 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/softfp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5054762 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/softfp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  283800 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/softfp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+dp/softfp/nano.specs
-rw-r--r-- 1 stephanos stephanos  854008 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  854008 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12900 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5057846 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  284056 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard/nano.specs
-rw-r--r-- 1 stephanos stephanos  853640 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/softfp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  853640 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/softfp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12900 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/softfp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5057630 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/softfp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  284048 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/softfp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main+fp/softfp/nano.specs
-rw-r--r-- 1 stephanos stephanos  851412 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libc_nano.a
-rw-r--r-- 1 stephanos stephanos  851412 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libg_nano.a
-rw-r--r-- 1 stephanos stephanos   12856 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/librdimon_nano.a
-rw-r--r-- 1 stephanos stephanos 5052094 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libstdc++_nano.a
-rw-r--r-- 1 stephanos stephanos  280620 Dec  2 13:37 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libsupc++_nano.a
-rw-r--r-- 1 stephanos stephanos     740 Dec  2 12:36 /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/nano.specs

/home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/include/newlib-nano:
total 8
-rw-r--r-- 1 stephanos stephanos 7211 Dec  2 12:47 newlib.h

/home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/sys-include/newlib-nano:
total 8
-rw-r--r-- 1 stephanos stephanos 7211 Dec  2 12:47 newlib.h

@stephanosio
Copy link
Contributor Author

stephanos@DOMINUS:~$ /opt/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-objdump -d /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/libc_nano.a | grep "<memcpy>:" -A 10
00000000 <memcpy>:
   0:   e2403001        sub     r3, r0, #1
   4:   e0812002        add     r2, r1, r2
   8:   e1510002        cmp     r1, r2
   c:   012fff1e        bxeq    lr
  10:   e4d1c001        ldrb    ip, [r1], #1
  14:   e5e3c001        strb    ip, [r3, #1]!
  18:   eafffffa        b       8 <memcpy+0x8>

lib_a-memcpy.o:     file format elf32-littlearm
stephanos@DOMINUS:~$ /opt/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-objdump -d /home/stephanos/Dev/x-tools/arm-zephyr-eabi/arm-zephyr-eabi/lib/libc.a | grep "<memcpy>:" -A 10
00000000 <memcpy>:
   0:   e52db004        push    {fp}            ; (str fp, [sp, #-4]!)
   4:   e28db000        add     fp, sp, #0
   8:   e24dd024        sub     sp, sp, #36     ; 0x24
   c:   e50b0018        str     r0, [fp, #-24]  ; 0xffffffe8
  10:   e50b101c        str     r1, [fp, #-28]  ; 0xffffffe4
  14:   e50b2020        str     r2, [fp, #-32]  ; 0xffffffe0
  18:   e51b3018        ldr     r3, [fp, #-24]  ; 0xffffffe8
  1c:   e50b3008        str     r3, [fp, #-8]
  20:   e51b301c        ldr     r3, [fp, #-28]  ; 0xffffffe4
  24:   e50b300c        str     r3, [fp, #-12]

stephanosio added a commit to stephanosio/zephyr-sdk-ng that referenced this pull request Dec 2, 2019
This commit adds the patches for the series of commits required to
support building the 'nano' variant of C/C++ runtime libraries.

This is a temporary commit and should be removed once the upstream PR
gets merged (see crosstool-ng/crosstool-ng#1279).

Signed-off-by: Stephanos Ioannidis <[email protected]>
@stephanosio
Copy link
Contributor Author

CI result for this patch on Zephyr SDK repository:
https://app.shippable.com/github/zephyrproject-rtos/sdk-ng/runs/347/summary

stephanosio added a commit to stephanosio/zephyr that referenced this pull request Dec 2, 2019
NEWLIB_LIBC_NANO was defined only for gnuarmemb toolchain because
Zephyr SDK did not support the newlib nano variant (as defined by
nano.specs) due to the inherent limitations of crosstool-ng, which is
used to build the toolchains.

Since crosstool-ng/crosstool-ng#1279 added support for the nano C/C++
runtime library variant and this change was introduced to the Zephyr
SDK through zephyrproject-rtos#153, it is no longer necessary to
restrict the newlib nano variant to gnuarmemb toolchain only.

Signed-off-by: Stephanos Ioannidis <[email protected]>
@stephanosio
Copy link
Contributor Author

Force pushing to allow optional target toolchain library stripping using STRIP_TARGET_TOOLCHAIN_LIBRARIES.

stephanosio added a commit to stephanosio/zephyr-sdk-ng that referenced this pull request Dec 4, 2019
This commit adds the patches for the series of commits required to
support building the 'nano' variant of C/C++ runtime libraries.

This is a temporary commit and should be removed once the upstream PR
gets merged (see crosstool-ng/crosstool-ng#1279).

Signed-off-by: Stephanos Ioannidis <[email protected]>
@nolange
Copy link
Contributor

nolange commented Dec 6, 2019

Gonna try this PR when I got some time. Got some comments:

in regards to the commit Assume '-O2' by default for building gcc target libraries,
a way easier fix would be to simply add the default in front.

CFLAGS_FOR_TARGET="-g -O2 ${CT_TARGET_CFLAGS}" 
CXXFLAGS_FOR_TARGET="-g -O2 ${CT_TARGET_CFLAGS}" 

Further the strip target files doesn't really fit in this PR, and I don't see why you would not just build the target files with -g0, as this would be faster. There is ${CT_TARGET}-strip aswell, which should be more robust than removing a list of sections

@stephanosio
Copy link
Contributor Author

stephanosio commented Dec 7, 2019

in regards to the commit Assume '-O2' by default for building gcc target libraries,
a way easier fix would be to simply add the default in front.

IIRC, there was something weird happening when I did that initially. This was while I was trying to fix multiple problems at once, so I will check again and see if it works now.

Further the strip target files doesn't really fit in this PR

I put it here mainly because the unstripped libs were simply too big and, with the multilibs and the additional nano variant, it was adding hundreds of megabytes to the final toolchain package.

If you prefer, I could move this commit to a separate PR.

I don't see why you would not just build the target files with -g0, as this would be faster.

Thanks to mt-ospace, -g0 will be overridden to -g (i.e. -g2) when --enable-optspace is specified:

https://github.com/gcc-mirror/gcc/blob/68c814f187c97e0c1a8cdc85c0da2207250ba66f/config/mt-ospace#L2-L3

That aside, the gcc (and other GNU toolchains) people seem to think that all runtime libs should be initially built with debugging information and stripped later if necessary, so I thought I would make it go with that flow.

A similar discussion was made in the newlib mailing list (which uses the same build system as gcc):
https://sourceware.org/ml/newlib/2019/msg00648.html

There is ${CT_TARGET}-strip aswell, which should be more robust than removing a list of sections

One problem with strip --strip-debug is that it removes all debug sections even including .debug_frame and this breaks stack unwinding for some archs.

This is also the way it is done in the GNU ARM Embedded build script (i.e. using objcopy instead of strip to remove a list of unneeded sections), supposedly for that very reason.

I am not aware of any way to force strip to not remove a specific section; if anyone does, please advise.

@stephanosio
Copy link
Contributor Author

in regards to the commit Assume '-O2' by default for building gcc target libraries,
a way easier fix would be to simply add the default in front.

IIRC, there was something weird happening when I did that initially. This was while I was trying to fix multiple problems at once, so I will check again and see if it works now.

Simply prepending -g -O2 to the target CFLAGS works now, the issue must have been due to some other problem at the time.

Force pushing to address this.

stephanosio added a commit to stephanosio/zephyr-sdk-ng that referenced this pull request Dec 7, 2019
This commit adds the patches for the series of commits required to
support building the 'nano' variant of C/C++ runtime libraries.

This is a temporary commit and should be removed once the upstream PR
gets merged (see crosstool-ng/crosstool-ng#1279).

Signed-off-by: Stephanos Ioannidis <[email protected]>
@nolange
Copy link
Contributor

nolange commented Dec 7, 2019

in regards to the commit Assume '-O2' by default for building gcc target libraries,
a way easier fix would be to simply add the default in front.

IIRC, there was something weird happening when I did that initially. This was while I was trying to fix multiple problems at once, so I will check again and see if it works now.

Further the strip target files doesn't really fit in this PR

I put it here mainly because the unstripped libs were simply too big and, with the multilibs and the additional nano variant, it was adding hundreds of megabytes to the final toolchain package.

If you prefer, I could move this commit to a separate PR.

Just to avoid misunderstanding, I am not maintainer of this project. I think however that small PR will get included faster.

I don't see why you would not just build the target files with -g0, as this would be faster.

Thanks to mt-ospace, -g0 will be overridden to -g (i.e. -g2) when --enable-optspace is specified:

https://github.com/gcc-mirror/gcc/blob/68c814f187c97e0c1a8cdc85c0da2207250ba66f/config/mt-ospace#L2-L3

Not possibe to append CFLAGS after that? There often are EXTRA Flags that come after, and options like --enable-cxx-flags

That aside, the gcc (and other GNU toolchains) people seem to think that all runtime libs should be initially built with debugging information and stripped later if necessary, so I thought I would make it go with that flow.

Not really unreasonable, I like this aswell so I can split the debuginfo into separate files and install as needed.

A similar discussion was made in the newlib mailing list (which uses the same build system as gcc):
https://sourceware.org/ml/newlib/2019/msg00648.html

There is ${CT_TARGET}-strip aswell, which should be more robust than removing a list of sections

One problem with strip --strip-debug is that it removes all debug sections even including .debug_frame and this breaks stack unwinding for some archs.

When do you need stack-unwinding? From the program itself you should use .ARM.exidx with -funwind-frames, for the debugger you need, well.. a debugger anyway so debuginfo makes sense (potentially only -g1).
But its an interesting argument I haven't thought about, this definitely comes at cost of more memory used

This is also the way it is done in the GNU ARM Embedded build script (i.e. using objcopy instead of strip to remove a list of unneeded sections), supposedly for that very reason.

I am not aware of any way to force strip to not remove a specific section; if anyone does, please advise.

The sections might vary across architectures/versions, I would make a special case for ARM (etc) that arent served well with strip.

galak pushed a commit to zephyrproject-rtos/sdk-ng that referenced this pull request Dec 9, 2019
This commit adds the patches for the series of commits required to
support building the 'nano' variant of C/C++ runtime libraries.

This is a temporary commit and should be removed once the upstream PR
gets merged (see crosstool-ng/crosstool-ng#1279).

Signed-off-by: Stephanos Ioannidis <[email protected]>
stephanosio added a commit to stephanosio/zephyr-sdk-ng that referenced this pull request Dec 20, 2019
This commit adds a patch for supporting the newlib retargetable
locking configuration in the crosstool-ng.

The patch is derived from the upstream pull request for the
retargetable locking configuration (crosstool-ng/crosstool-ng#1284)
cherry-picked on top of the newlib nano variant pull request
(crosstool-ng/crosstool-ng#1279).

The work branch for this patch is available at the following location:
stephanosio/crosstool-ng/newlib_nano_variant_with_retargetable_locking

Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit adds the new configuration option 'LIBC_NANO_NEWLIB' for
specifying the additional 'nano' variant of newlib to be built.

In addition, the existing newlib 'LIBC_NEWLIB_...' configs are mirrored
as 'LIBC_NANO_NEWLIB_...' in order to accommodate specifying different
build configurations for the nano variant.

For more details, refer to the issue zephyrproject-rtos/sdk-ng#152.

Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit updates the newlib build script to build the additional
newlib nano variant using the nano variant-specific build options.

Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit adds the new configuration option 'CC_GCC_LIBSTDCXX_NANO'
for specifying the additional 'nano' variant of libstdc++ to be built
and updates the gcc build script to build the stdlibc++ nano variant
with the '-Os' (optimise for size) option flag.

The libstdc++ nano variant (lib{std,sup}c++_nano.a) is specified by
'nano.specs' alongside the libc nano variant (lib{c,g}_nano.a).

Signed-off-by: Stephanos Ioannidis <[email protected]>
The gcc target libraries (e.g. libstdc++) are currently built without
any optimisation flag when 'CT_CC_GCC_ENABLE_TARGET_OPTSPACE' is not
enabled and default to '-O0' unless user explicitly specifies an
optimisation flag.

This commit updates the gcc build script to assume '-O2' for building
target libraries unless user provides a different optimisation flag.

Note also that this is the default behaviour for gcc when
C[XX]FLAGS_FOR_TARGET is not overridden.

Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit adds an option to strip the target toolchain libraries
(e.g. libc, libstdc++) of any unneeded or debugging information.

Stripping is enabled by default as it is often desirable to reduce the
overall toolchain size when producing a release.

Signed-off-by: Stephanos Ioannidis <[email protected]>
@stephanosio
Copy link
Contributor Author

Force pushing to resolve merge conflict with #1284 (added retargetable locking configuration for the nano variant as well).

Comment on lines +135 to +141
if [ "${CT_LIBC_NANO_NEWLIB_IO_FLOAT}" = "y" ]; then
newlib_opts+=( "--enable-newlib-io-float" )
if [ "${CT_LIBC_NANO_NEWLIB_IO_LDBL}" = "y" ]; then
newlib_opts+=( "--enable-newlib-io-long-double" )
else
newlib_opts+=( "--disable-newlib-io-long-double" )
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think that this kind of dependencies between LIBC_NANO_NEWLIB_IO_FLOAT and LIBC_NANO_NEWLIB_LDBL is better expressed in the Kconfig. They predated the introduction of yn_args, but if they start to propagate, there is no reason not to fold them into this array.

  2. I don't like that the yn_args variable is global. Granted, it was like that before - this was concealed by having it defined and used by the same function. But I'd prefer having a single list of all newlib options - if necessary, with the third field identifying whether this flag is applicable to the normal variant of newlib, or to the nano variant, or to both. If it must be global, name it in a way that avoid clashes with other components.

  3. I'd prefer the names of the new variables to start with NEWLIB_NANO rather than NANO_NEWLIB. After all, this is still a part of the newlib configuration.

  4. I must be missing something, but I don't see how this new code builds the "nano" variant while the existing code builds a "full" library. The only differences I see are the names of the options governing the newlib configuration. Can you explain? If there is some difference, it should be highlighted with a comment in the code. Moreover, I think that both variants can be handled by the same backend, just have newlib_main_full/newlib_main_nano pass the necessary bits to that backend, e.g.:

newlib_main_full()
{
    newlib_main_backend NEWLIB
}

newlib_main_nano()
{
    newlib_main_backend NEWLIB_NANO
}

newlib_main_backend()
{
    local kcfg_prefix=$1
    ...
    for ynarg in $yn_args; do
        var="CT_LIBC_${kcfg_prefix}_${ynarg%:*}"
    ...
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ad 4.: nano is just a set of libraries with different options which you can pick at compile time. Linaro, ARM and many ARM Toolchains offer them, look at https://github.com/FreddieChopin/bleeding-edge-toolchain for example.

There is no difference to a full toolchain, but you don't need to compile twice for host.

fi

# Assume '-O2' by default for building target libraries.
cflags_for_target="-g -O2 ${cflags_for_target}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the default for TARGET_CFLAGS in Kconfig, this will be more obvious to the user. Needs to be tested more thoroughly, though, as it will affect not just gcc build.

Copy link
Contributor

@nolange nolange Dec 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An argument against that would be that someone like me could expect the flags work identical to "manual" builds.
With empty flags: pick the packages defaults (which might well be different).

Prepending the package defaults seems so be the most sane to me, as you could eg. easily disable debugging info with -g0 while leaving the respective optimization defaults untouched, or adding -flto for adding LTO info.

Then maybe we can fixup all the small deficiencies and differences in packages, see #1267, #1270, #1280

galak pushed a commit to zephyrproject-rtos/sdk-ng that referenced this pull request Jan 8, 2020
This commit adds a patch for supporting the newlib retargetable
locking configuration in the crosstool-ng.

The patch is derived from the upstream pull request for the
retargetable locking configuration (crosstool-ng/crosstool-ng#1284)
cherry-picked on top of the newlib nano variant pull request
(crosstool-ng/crosstool-ng#1279).

The work branch for this patch is available at the following location:
stephanosio/crosstool-ng/newlib_nano_variant_with_retargetable_locking

Signed-off-by: Stephanos Ioannidis <[email protected]>
@abrodkin
Copy link
Contributor

Just FYI, GCC might be aware of t least "nano-formatted-io" (see #1437).
And given how this is implemented now there is no way to dynamically determine which type of Newlib (nano- or not) we're going to use.

I'm not saying above "feature" of the GCC should stop us from building nano flavors of run-time libs along with their "normal" counterpart, but given said mismatch (between Newlib & GCC) leads to additional 22 failures in GCC's DejaGnu suit (see below), it might need some love to get fixed and not fool people looking at regressions.

These're those extra failures for the case of Newlib configured with --enable-newlib-nano-formatted-io while GCC was not:

FAIL: gcc.c-torture/execute/920501-8.c   -O0  execution test
FAIL: gcc.c-torture/execute/920501-8.c   -O1  execution test
FAIL: gcc.c-torture/execute/920501-8.c   -O2  execution test
FAIL: gcc.c-torture/execute/920501-8.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
FAIL: gcc.c-torture/execute/920501-8.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
FAIL: gcc.c-torture/execute/920501-8.c   -O3 -g  execution test
FAIL: gcc.c-torture/execute/920501-8.c   -Os  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -O0  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -O1  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -O2  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -O3 -g  execution test
FAIL: gcc.c-torture/execute/930513-1.c   -Os  execution test
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -O0
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -O1
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -O2
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -O2 -flto -fno-use-linker-plugin -flto-partition=none
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -O3 -g
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -Og -g
FAIL: gcc.c-torture/execute/ieee/920810-1.c execution,  -Os

And BTW @stephanosio, @galak do you have any interest in resurrecting your work on this one anytime soon?

@keith-packard
Copy link
Contributor

keith-packard commented Jan 12, 2021

I've proposed a different PR that makes newlib-nano into a companion library so that you can build multiple C libraries and select which one you want when building applications. The initial PR, #1444, adds picolibc as a companion library, but once we decide if that's the right way forward, and get that fixed up and merged, then adding newlib-nano is all ready to go.

@abrodkin
Copy link
Contributor

@keith-packard, @cpackham now #1444 is merged. Any hints on what needs to be done for moving a special "nano" flavor of Newlib into companion libs?

@keith-packard
Copy link
Contributor

I've got something that builds in my nano-companion branch, but I haven't managed to test it yet as I'm having trouble building the zephyr configuration of crosstool-ng due to python package version differences. If you want to explore that, please look here:

https://github.com/keith-packard/crosstool-ng/tree/nano-companion

@galak
Copy link
Contributor

galak commented Jan 14, 2021

I've got something that builds in my nano-companion branch, but I haven't managed to test it yet as I'm having trouble building the zephyr configuration of crosstool-ng due to python package version differences. If you want to explore that, please look here:

https://github.com/keith-packard/crosstool-ng/tree/nano-companion

what's the python issue you are running into?

@keith-packard
Copy link
Contributor

what's the python issue you are running into?

Looks like something is looking for python3.8, but that version isn't working correctly in my debian unstable environment:

[ALL  ]    checking for python3.8... /usr/bin/python3.8
[ALL  ]    Traceback (most recent call last):
[ALL  ]      File "/home/keithp/zephyrproject/sdk-ng/build/build_arm/.build/arm-zephyr-eabi/src/gdb/gdb/python/python-config.py", line 7, in <module>
[ALL  ]        from distutils import sysconfig
[ALL  ]    ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)
[ERROR]    configure: error: failure running python-config --includes
[ERROR]    make[2]: *** [Makefile:9199: configure-gdb] Error 1
[ALL  ]    make[2]: Leaving directory '/home/keithp/zephyrproject/sdk-ng/build/build_arm/.build/arm-zephyr-eabi/build/build-gdb-cross'
[ERROR]    make[1]: *** [Makefile:851: all] Error 2
[ALL  ]    make[1]: Leaving directory '/home/keithp/zephyrproject/sdk-ng/build/build_arm/.build/arm-zephyr-eabi/build/build-gdb-cross'
[ERROR]  
[ERROR]  >>
[ERROR]  >>  Build failed in step 'Installing cross-gdb'
[ERROR]  >>        called in step '(top-level)'
[ERROR]  >>
[ERROR]  >>  Error happened in: CT_DoExecLog[scripts/functions@376]
[ERROR]  >>        called from: do_gdb_backend[scripts/build/debug/300-gdb.sh@282]
[ERROR]  >>        called from: do_debug_gdb_build[scripts/build/debug/300-gdb.sh@59]
[ERROR]  >>        called from: do_debug[scripts/build/debug.sh@35]
[ERROR]  >>        called from: main[scripts/crosstool-NG.sh@695]
[ERROR]  >>

@abrodkin
Copy link
Contributor

Got everything nicely built from https://github.com/keith-packard/crosstool-ng/tree/nano-companion and see a second instance of Newlib libs in newlib-nano subfolder.

And thanks to auto-generated nano.specs compiler finds requested "nano" libs in that newlib-nano location.

@galak
Copy link
Contributor

galak commented Jan 14, 2021

Looks like something is looking for python3.8, but that version isn't working correctly in my debian unstable environment:

Ah, we build a version of GDB with python3.8 support. I'd suggest to just disable GDB being built as its not related to the newlib.

@keith-packard
Copy link
Contributor

Ah, we build a version of GDB with python3.8 support. I'd suggest to just disable GDB being built as its not related to the newlib.

I changed the python3.8 invocation to just use python3 and it worked just fine. Maybe improving crosstool-ng to allow for 'python >= 3.8' somehow would be useful?

@keith-packard
Copy link
Contributor

And thanks to auto-generated nano.specs compiler finds requested "nano" libs in that newlib-nano location.

Cool! Now to figure out if the resulting toolchain is actually useful :-)

@abrodkin
Copy link
Contributor

May we close this now with #1447 merged?

@galak
Copy link
Contributor

galak commented Apr 15, 2021

May we close this now with #1447 merged?

Ditto. I think this can be closed out.

@cpackham
Copy link
Contributor

The consensus seems that we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants