Code Monkey home page Code Monkey logo

Comments (11)

galak avatar galak commented on May 27, 2024

Did you enable CONFIG_NEWLIB_LIBC, for the libm.a support. By default we use the minlibc in zephyr has NO libm support.

from sdk-ng.

galak avatar galak commented on May 27, 2024

If I try test w/CONFIG_NEWLIB_LIBC things seem to build correctly.

from sdk-ng.

alexeRadu avatar alexeRadu commented on May 27, 2024

Yes, you are right. It worked when using CONFIG_NEWLIB_LIBC.

from sdk-ng.

alexandru-porosanu-nxp avatar alexandru-porosanu-nxp commented on May 27, 2024

I agree that using CONFIG_NEWLIB_LIBC solves the problem at hand. But I find it awkward that there's no feedback at link time that you're linking with the wrong library; what @alexeRadu noticed is that if using -lm and no newlibc, the hello_world compiles (and links) properly but when running on the target (M0+ core), he gets an invalid instruction exception.
This looks like a principle of least astonishment issue: the user will have no idea why his software is failing and no hint on how to track it down. I think there should be some sort of link-time warning when using -lm and minlibc. @galak what do you think, does this make any sense?

from sdk-ng.

galak avatar galak commented on May 27, 2024

With the zephyr toolchain I get:

/opt/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/../../../../arm-zephyr-eabi/bin/ld: ../app/libapp.a(main.c.obj): in function `main':
/home/galak/git/zephyr/samples/hello_world/src/main.c:13: undefined reference to `trunc'
collect2: error: ld returned 1 exit status
make[2]: *** [zephyr/CMakeFiles/zephyr_prebuilt.dir/build.make:97: zephyr/zephyr_prebuilt.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:558: zephyr/CMakeFiles/zephyr_prebuilt.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

with the arm embedded toolchain I get (2018-q4):

/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: ../app/libapp.a(main.c.obj): in function `main':
/home/galak/git/zephyr/samples/hello_world/src/main.c:13: undefined reference to `trunc'
collect2: error: ld returned 1 exit status
make[2]: *** [zephyr/CMakeFiles/zephyr_prebuilt.dir/build.make:97: zephyr/zephyr_prebuilt.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:558: zephyr/CMakeFiles/zephyr_prebuilt.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

from sdk-ng.

galak avatar galak commented on May 27, 2024

With 2019-q3:

Memory region         Used Size  Region Size  %age Used
           FLASH:       10760 B       512 KB      2.05%
            SRAM:        3824 B       128 KB      2.92%
        IDT_LIST:          40 B         2 KB      1.95%
/opt/gcc-arm-none-eabi-8-2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: ../app/libapp.a(main.c.obj): in function `main':
/home/galak/git/zephyr/samples/hello_world/src/main.c:13: undefined reference to `trunc'
collect2: error: ld returned 1 exit status
make[2]: *** [zephyr/CMakeFiles/zephyr_prebuilt.dir/build.make:97: zephyr/zephyr_prebuilt.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:558: zephyr/CMakeFiles/zephyr_prebuilt.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

So I feel like we are seeing a link error.

from sdk-ng.

alexandru-porosanu-nxp avatar alexandru-porosanu-nxp commented on May 27, 2024

@galak, yes, you are correct: just compiling the hello_world.c without using any supplementary linker options, you'll receive the 'undefined reference' error. On the other hand, forcing "-lm" through target_ld_options() and declaring extern double trunc(double) will yield the correct result, without using CONFIG_NEWLIBC. But I'm not sure why me and @alexeRadu have seen the weird invalid instruction in this case.

So in short, we'll be using newlibc if we need trunc() or any other functions that are not available in minlibc.

from sdk-ng.

galak avatar galak commented on May 27, 2024

@galak, yes, you are correct: just compiling the hello_world.c without using any supplementary linker options, you'll receive the 'undefined reference' error. On the other hand, forcing "-lm" through target_ld_options() and declaring extern double trunc(double) will yield the correct result, without using CONFIG_NEWLIBC. But I'm not sure why me and @alexeRadu have seen the weird invalid instruction in this case.

when you say correct result what do you mean?

from sdk-ng.

alexandru-porosanu-nxp avatar alexandru-porosanu-nxp commented on May 27, 2024

I meant that calling trunc() yields the expected result and no exception is triggered.

from sdk-ng.

galak avatar galak commented on May 27, 2024

ok, let me know if you run into any other issues or cases where we can improve the developer experience.

from sdk-ng.

alexandru-porosanu-nxp avatar alexandru-porosanu-nxp commented on May 27, 2024

Sure, will do, thanks!

from sdk-ng.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.