undefined reference to _open when using libc with NCS 2.4.2 and above

Hello,

I am developing an application for a custom nrf52840 board. This application has been building and running without problems for nrf Connect SDK v 2.3.0

However, I recently tried to upgrade to NCS v2.5.0 and I get the below link-time error:

D:/ncs2/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp\libc.a(lib_a-openr.o): in function `_open_r':
openr.c:(.text._open_r+0x14): undefined reference to `_open'

Note that 

CONFIG_NEWLIB_LIBC=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
is set in my prj.conf. I also see these lines in autoconf.h: 
#define CONFIG_FULL_LIBC_SUPPORTED 1
#define CONFIG_MINIMAL_LIBC_SUPPORTED 1
#define CONFIG_NEWLIB_LIBC_SUPPORTED 1
#define CONFIG_PICOLIBC_SUPPORTED 1
#define CONFIG_NEWLIB_LIBC 1
#define CONFIG_HAS_NEWLIB_LIBC_NANO 1
I tried to downgrade to NCS 2.4.2, but it seems to have the same issue. However, no problems with NCS v2.3.0
Has something changed since NCS 2.4.2? Am I supposed to enable some other config flag as well, in order to use full newlib libc?
thanks
regards
pnc
Parents Reply
  • Hi Hakon,

    as suggested by you, I posted this to Zephyr issues forum. Here is the link:

    https://github.com/zephyrproject-rtos/zephyr/issues/66132

    This was the "helpful" response I got:

    ====================================================

    Thank you for reporting this. However - unless you are able to reproduce this issue with upstream Zephyr main - please report issues with the nRF Connect SDK (NCS) on the Nordic Semiconductor DevZone.

    ==================================================

    As mentioned previously, I already have tried it out with the latest development version of NCS 2.5.99-dev1 ( Zephyr 3.4.99). Unfortunately, you do not use upstream Zephyr, but a fork of Zephyr currently at 3.4.99, and it is clear that the Zephyr folk won't help me unless I can reproduce this with upstream Zephyr main (currently at 3.5.99).

    As my organization's hardware vendor, it is certainly your responsibility to fix this issue, rather than batting this down to Zephyr. 

Children
  • I checked out zephyr HEAD (commit 3d3b287b7908625dc8356ac3532d9b6943edbb50), and tried to compile this sample for board nrf52dk_nrf52832:
    hello_world_posix.zip

     

    It will fail with the following output:

    $ ninja
    [1/174] Preparing syscall dependency handling
    
    [3/174] Generating include/generated/version.h
    -- Zephyr version: 3.5.99 (/opt/repos/upstream-zephyr/zephyr), build: zephyr-v3.5.0-2646-g3d3b287b7908
    [10/174] Building C object CMakeFiles/app.dir/src/main.c.obj
    /opt/repos/upstream-zephyr/zephyr/samples/hello_world_posix/src/main.c: In function 'main':
    /opt/repos/upstream-zephyr/zephyr/samples/hello_world_posix/src/main.c:12:15: warning: unused variable 'f' [-Wunused-variable]
       12 |         FILE *f = fopen("posix.txt", "a");
          |               ^
    [168/174] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /opt/repos/upstream-zephyr/zephyr/samples/hello_world_posix/build/zephyr/zephyr_pre0.map 
    : && ccache /opt/zephyr-sdk/zephyr-sdk-0.16.0/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/opt/repos/upstream-zephyr/zephyr/samples/hello_world_posix/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/libarch__arm__core.a  zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a  zephyr/arch/arch/arm/core/mpu/libarch__arm__core__mpu.a  zephyr/lib/libc/newlib/liblib__libc__newlib.a  zephyr/lib/libc/common/liblib__libc__common.a  zephyr/lib/posix/liblib__posix.a  zephyr/soc/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/subsys/fs/libsubsys__fs.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/flash/libdrivers__flash.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/littlefs/libmodules__littlefs.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/zephyr-sdk/zephyr-sdk-0.16.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp"  -L/opt/repos/upstream-zephyr/zephyr/samples/hello_world_posix/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfp16-format=ieee  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  -lm  -Wl,-lc  -L"/opt/zephyr-sdk/zephyr-sdk-0.16.0/arm-zephyr-eabi/arm-zephyr-eabi"/lib/thumb/v7e-m/nofp  -Wl,-lgcc  -lc && cd /opt/repos/upstream-zephyr/zephyr/samples/hello_world_posix/build/zephyr && /usr/bin/cmake -E true
    /opt/zephyr-sdk/zephyr-sdk-0.16.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /opt/zephyr-sdk/zephyr-sdk-0.16.0/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp/libc.a(lib_a-openr.o): in function `_open_r':
    openr.c:(.text._open_r+0x14): undefined reference to `_open'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    

    If you use picolib instead of newlib, it will compile as expected.

     

    You can share this in the github issue if you'd like.

     

    Kind regards,

    Håkon

  • Thanks Hakon,

    I have posted your response back to Zephyr :-) 

    What is the approximate lead time between an issue getting fixed on Zephyr and it being incorporated into NCS? I cannot hand over the app to the internal customer until it builds with an official version of NCS.

  • Happy to help out.

    pnc2 said:
    What is the approximate lead time between an issue getting fixed on Zephyr and it being incorporated into NCS? I cannot hand over the app to the internal customer until it builds with an official version of NCS.

    We try to align with upstream zephyr as close as we can, and do this in regular intervals.

    I unfortunately cannot state when and if this issue will be resolved, as it has a upstream dependency.

    If in the future the issue is fixed in a non-released version, ie. on main: What can be done is to patch "sdk-zephyr" (ie. NCS) manually if upstream provides a workaround or fix to the issue. 

     

    You can use picolib instead of newlib, if that is a valid option in your project.

     

    Kind regards,

    Håkon

Related