sbrk.c: undefined reference to `end' in nrf connect SDK v2.4.0

Hi Team,

Earlier, we developed a library using nordic sdk v2.3.0 on nRF5340 TF-M secure environment. Now we planned to switch from nordic sdk v2.3.0 to v2.4.0.

While trying to compile our source code using nordic sdk v2.4.0, we observed the linker error (undefined reference to end) but this error is not observed in nordic sdk v2.3.0.

Linker Error:

c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.exe: c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/lib/thumb/v8-m.main+fp/hard\libnosys.a(sbrk.o): in function `_sbrk':
sbrk.c:(.text._sbrk+0x1c): undefined reference to `end'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

I could find the same problem in below link(ticket). But we are not using malloc or any Dynamic memory related functions anywhere in the code. But unable to understand why we are getting this error.

https://devzone.nordicsemi.com/f/nordic-q-a/101643/undefined-reference-to-end-with-nrf-connect-sdk-v2-4-0

After adding CONFIG_DEBUG=y, this error is resolved. As you suggested, we are unwilling to use this.

For v2.3.0, In CMakeLists.txt we were using below libs

target_link_libraries(tfm_lib
    PRIVATE
       tfm_secure_api
       platform_s
       psa_interface
       secure_fw
       tfm_psa_rot_partition_crypto
)

 

For v2.4.0, we tried with below params

target_link_libraries(tfm_lib
    PRIVATE
       tfm_secure_api
       platform_s
       psa_interface
       secure_fw
       tfm_psa_rot_partition_crypto
)

and 

target_link_libraries(tfm_lib
    PRIVATE
        tfm_sprt
        platform_s
)

Anything need to added in CMakeLists.txt or prj.conf to fix the error(undefined reference to end). Could you please point out if we missed anything.

Note: We are using attestation and key derivation APIs in code.

Parents
  • Hello,

    The developer I talked to suspects this is related to the cc3xx library. Please open the ncs/v2.4.0/ directory in a terminal and run "$ git status && git describe --tags" to verify that the 'nrfxlib' repo which contains this libary is on the v2.4.0 tag.

    Thanks,

    Vidar

  • Hello Vidar, Yes deleted. I thought to try more from my side, so.
    It's on the v2.4.0 tag

    user@WIN MINGW64 /c/ncs/v2.4.0/nrfxlib ((v2.4.0))
    $ git status && git describe --tags
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    v2.4.0
    

    After digging into the problem we found that, this error is occuring in 2 cases.

    1) when we are using variable argument list functions like va_start, va_end (we are using these for logging). When I disabled this log module, error got resolved.

    2) when we are using UART related code. We are using UART to communicate between nrf5340 device and windows PC.

    In prj.conf, we are using

    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_TFM_LOG_LEVEL_SILENCE=y


    In app code, 
    const struct device *uart1 = DEVICE_DT_GET(DT_NODELABEL(uart1));

    Could you plz suggest some solution for this?

Reply
  • Hello Vidar, Yes deleted. I thought to try more from my side, so.
    It's on the v2.4.0 tag

    user@WIN MINGW64 /c/ncs/v2.4.0/nrfxlib ((v2.4.0))
    $ git status && git describe --tags
    HEAD detached at refs/heads/manifest-rev
    nothing to commit, working tree clean
    v2.4.0
    

    After digging into the problem we found that, this error is occuring in 2 cases.

    1) when we are using variable argument list functions like va_start, va_end (we are using these for logging). When I disabled this log module, error got resolved.

    2) when we are using UART related code. We are using UART to communicate between nrf5340 device and windows PC.

    In prj.conf, we are using

    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_TFM_LOG_LEVEL_SILENCE=y


    In app code, 
    const struct device *uart1 = DEVICE_DT_GET(DT_NODELABEL(uart1));

    Could you plz suggest some solution for this?

Children
  • Since you have CONFIG_TFM_LOG_LEVEL_SILENCE enabled, the printf implementation in TF-M will not be included. Instead, you will get the printf function from the C standard library, which requires heap. Do you get the same error if you remove CONFIG_TFM_LOG_LEVEL_SILENCE=y?

  • Hi,

    1) We have 2 Apps(One is without UART and another is with UART).  we are using CONFIG_TFM_LOG_LEVEL_SILENCE=y only in UART app. 
    As per below ticket, if we remove CONFIG_TFM_LOG_LEVEL_SILENCE=y, we used to get undefined reference errors till v2.3.0 as we are using uart1(the same is used by TFM).Now with v2.4.0 UART app is compiling even without this config.

    nonsecure app with uart support

    2
    ) Regarding "undefined reference to `end' "  -- We debugged each line. This error is caused by 3 functions in our code i.e localtime, snprintf, vsnprintf (printf working fine). so we replaced these 3 APIs with custom implementation. Now it got compiled.

    Issue is fixed for us. May be could you plz check why these 3 apis giving this error even if we don't use CONFIG_TFM_LOG_LEVEL_SILENCE=y

  • The new TF-M version included in SDK 2.4.0 does not allocate heap by default when you are doing a non-debug build. As a result, any implementations trying to use the C library heap will encounter a linker error, as you have experienced.

Related