Migration to NCS 3.2.4 causes pthread_attr_t error and RAM overflow with Picolibc

Hi Nordic team,

We are currently migrating our project from nRF Connect SDK v3.1.1 to v3.2.4 on the nRF9160.

Our application was working without issues on v3.1.1. After upgrading to NCS 3.2.4, we encountered the following compilation error:

In file included from C:/ncs/v3.2.4/zephyr/include/zephyr/posix/time.h:62,
from C:/ncs/v3.2.4/nrf/lib/date_time/date_time_modem.c:9:
C:/ncs/v3.2.4/zephyr/include/zephyr/posix/signal.h:102:9: error: unknown type name 'pthread_attr_t'
102 | pthread_attr_t *sigev_notify_attributes;

After investigation, we determined that this issue is related to NEWLIB_LIBC no longer being supported in NCS 3.2.4. To resolve this, we switched to Picolibc.

However, enabling Picolibc introduced a new problem:

c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr\zephyr_pre0.elf section `noinit' will not fit in region `RAM'
c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `RAM' overflowed by 55008 bytes

This is significantly beyond our available memory budget and prevents the application from running.

We are enabling picolib using the following configs 

CONFIG_PICOLIBC=y

CONFIG_COMMON_LIBC_MALLOC=y

CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=512

Any guidance or best practices for handling this migration would be greatly appreciated.

Thanks!

  • Hi,

    Regarding the compilation error you are getting, can you try to add this to your prj.conf:

    CONFIG_POSIX_THREADS=y

    As I believe POSIX types are only compiled in when explicitly enabled. Do let me know if it works.

    And your RAM overflow issue is a separate problem that would requires further diagnosis, it would be helpful if we could first get the RAM usage for all compiled objects which you could check by running the 'west build -t ram_report' after attempting a build.

    Best Regards,
    Syed Maysum

  • Hi, adding CONFIG_POSIX_THREADS=y also results in RAM overflow of 55KB.

  • Hi,

    Okay thanks for trying it out. To help diagnose the RAM overflow, can you please share:

    - Output of 'west build -t ram_report'
    - The value of CONFIG_HEAP_MEM_POOL_SIZE from build/zephyr/.config

    Best Regards,
    Syed Maysum

  • Sorry for the late reply, 
    - CONFIG_HEAP_MEM_POOL_SIZE = 4096 in the build/relay/zephyr/.config file

    - The build is not successful in ncs 3.2.4 so i get this error when i try to generate a ram_report

    west build: running target ram_report
    [0/18] Performing build step for 'tfm'
    ninja: no work to do.
    [2/8] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map C:/Github/RelayLwM2MClient/relay/build_v3_release/relay/zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\ncs\toolchains\fd21892d0f\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -gdwarf-4 -Os @CMakeFiles\zephyr_pre0.rsp -o zephyr\zephyr_pre0.elf -Lc:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp -lc -lgcc && cmd.exe /C "cd /D C:\Github\RelayLwM2MClient\relay\build_v3_release\relay\zephyr && C:\ncs\toolchains\fd21892d0f\opt\bin\cmake.exe -E true""
    c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr\zephyr_pre0.elf section `noinit' will not fit in region `RAM'
    c:/ncs/toolchains/fd21892d0f/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: region `RAM' overflowed by 56400 bytes
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\fd21892d0f\opt\bin\cmake.EXE' --build 'c:\Github\RelayLwM2MClient\relay\build_v3_release\relay' --target ram_report

    - I can however generate a ram_report for ncs 3.1.1 (without POSIX and PICOLib configurations), here is the report from NCS 3.1.1

     5140.ram_report.txt

  • Hi,

    Thanks for sharing the ram_report. Looking at your NCS 3.1.1 build, your application is already using around 246KB out of 256KB of available RAM, leaving very little headroom. This means the RAM overflow in NCS 3.2.4 is not purely a Picolibc issue, but a result of the NCS 3.2 framework having a slightly larger footprint on an already near-full memory budget.

    To fix this we need to profile and reduce your thread stack sizes. Please add the following to your prj.conf and run it on your NCS 3.1.1 build:

    CONFIG_THREAD_ANALYZER=y
    CONFIG_THREAD_ANALYZER_USE_PRINTK=y
    CONFIG_THREAD_ANALYZER_AUTO=y
    CONFIG_THREAD_NAME=y
    CONFIG_INIT_STACKS=y

    You may also read this guide that walks through exactly how to use the Thread Analyzer and reduce memory consumption: Memory Optimization with the nRF Connect SDK 

    Based on your report, the largest consumers in your noinit section are your BLE thread stacks combined, net_buf_data_pkt_pool, and send_from_flash_to_cloud. The Thread Analyzer output will help to determine exactly how much each thread stack can be reduced.

    Best Regard,
    Syed Maysum

Related