interoberlin / nRF51-playground

Playground for our nRF51822 Bluetooth Low Energy experiments
https://www.interoberlin.de/blog/category/projects/ble/
9 stars 2 forks source link

undefined reference to `__aeabi_idivmod' #8

Closed matthiasbock closed 8 years ago

matthiasbock commented 8 years ago
/usr/bin/arm-none-eabi-ld -L /usr/lib/gcc/arm-none-eabi/4.8/armv6-m/ -L /usr/lib/arm-none-eabi/newlib/armv6-m/ -T nrf51.ld nrf51_startup.o system_nrf51.o heap.o delay.o fifo.o uart.o radio.o demo_radio.o -o demo_radio.elf
demo_radio.o: In function `main':
/home/code/nRF51822/playground/demo_radio.c:84: undefined reference to `__aeabi_idivmod'
Makefile:50: recipe for target 'demo_radio.elf' failed
make: *** [demo_radio.elf] Error 1
matthiasbock commented 8 years ago

Traced to the following line:

channel_index = (channel_index + 1) % 3;
matthiasbock commented 8 years ago

A similar problem occurs when trying to compile demo_radio.c with timers:

make all 
/usr/bin/arm-none-eabi-ld -nostartfiles -nostdlib -static -lgcc -L /usr/lib/gcc/arm-none-eabi/4.8/armv6-m/ -T nrf51.ld nrf51_startup.o system_nrf51.o strings.o heap.o fifo.o uart.o delay.o timer.o radio.o demo_radio.o -o demo_radio.elf
timer.o: In function `us2ticks':
/home/code/nRF51822/playground/timer.c:58: undefined reference to `__aeabi_lmul'
Makefile:51: recipe for target 'demo_radio.elf' failed
/home/code/nRF51822/playground/timer.c:58: undefined reference to `__aeabi_uldivmod'
timer.o: In function `ticks2us':
/home/code/nRF51822/playground/timer.c:63: undefined reference to `__aeabi_lmul'
/home/code/nRF51822/playground/timer.c:63: undefined reference to `__aeabi_uldivmod'
make: *** [demo_radio.elf] Error 1
matthiasbock commented 8 years ago

Using arm-linux-gnueabi-gcc-4.7 instead of arm-none-eabi-gcc-4.8 did not help...

matthiasbock commented 8 years ago

Compiles after including https://github.com/bobbl/libaeabi-cortexm0.git and adding the --start-group parameter to linker to enable iterated symbol reference lookup.

matthiasbock commented 8 years ago

New problem:

(gdb) load
Loading section .data, size 0x1c lma 0x20000000
Loading section .text, size 0x1710 lma 0x0
Loading section .rodata, size 0x164 lma 0x1710
Loading section .ARM.exidx, size 0x8 lma 0x1874
Start address 0x0, load size 6296
Transfer rate: 3 KB/sec, 1574 bytes/write.
(gdb) c
Continuing.
nrf51.cpu -- clearing lockup after double fault
Program received signal SIGINT, Interrupt.
0xfffffffe in ?? ()
(gdb) 
matthiasbock commented 8 years ago

Turns out, the --start-group parameter before -lgcc is sufficient to fix the undefined reference problems, the additional library is not required.

However, there seems to be a new section .ARM.exidx in the binary now, which is not set up by the linker script yet. Probably related to this section or the stack in general, now a double fault occurs at the second(?) instruction after load.

matthiasbock commented 8 years ago