Comments (11)
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.
If I try test w/CONFIG_NEWLIB_LIBC
things seem to build correctly.
from sdk-ng.
Yes, you are right. It worked when using CONFIG_NEWLIB_LIBC
.
from sdk-ng.
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.
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.
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.
@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, 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.
I meant that calling trunc() yields the expected result and no exception is triggered.
from sdk-ng.
ok, let me know if you run into any other issues or cases where we can improve the developer experience.
from sdk-ng.
Sure, will do, thanks!
from sdk-ng.
Related Issues (20)
- arc binutils generates incorrect thread local storage (TLS) offsets HOT 11
- qemu-system-arc has bugs in delay-slot handling that are fixed upstream HOT 1
- Illegal load of EXC_RETURN into PC issue while using spi and ble in NRF52840DK HOT 1
- Thread awareness is not available on QEMU targets HOT 1
- runpath not set for libusb.so HOT 2
- arc soft float multiply error HOT 3
- Picolibc printf options in SDK 'integer only' variant?
- picolibc: Soft-float math functions access the FPU on SPARC HOT 3
- GitHub release info for 0.16.3 mentions wrong version of picolibc HOT 1
- Releases page does not have links to the full version HOT 1
- "Bus fault on vector table read" using SDK versions later than 0.16.0-beta1
- Upgrade to QEMU 8.1
- does SDK support riscv vector extension HOT 1
- maintainability: properly document the build process HOT 13
- Individual toolchain installation should be ignored for full_sdk HOT 1
- `setup.sh` cannot find applications on PATH HOT 2
- [GDB] Debugger seems to crash when stepping inside an IRQ handler HOT 4
- Broken links in Zephyr SDK 0.16.5-rc1release page HOT 1
- Update Zephyr SDK to be based upon GCC 14 HOT 7
- pokysdk provides an older Verison of GLIBC than required by system HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk-ng.