原文地址:http://hi.baidu.com/vim_li/blog/item/5ae3f839749701e515cecbc9.html
1、剛剛完成bootloader部分的框架及Makefile,寫了幾個driver,編譯后,鏈接時,出現(xiàn)下面錯誤:
ipl/ipl.o: In function `low_level_init':
ipl.c:(.text+0x28): relocation truncated to fit: R_ARM_CALL against symbol `system_clk_init' defined in .text section in /work/new_plat/bootloader/drivers/libdrivers.a(clock.o)
ipl.c:(.text+0x2c): relocation truncated to fit: R_ARM_CALL against symbol `serial_init' defined in .text section in /work/new_plat/bootloader/drivers/libdrivers.a(serial.o)
make: *** [bootloader] Error 1
原因:外部函數(shù)調用時,指令跳轉返回太長,超出了ARM instruction的范圍(The maximum branch is +/- 32Mbytes in ARM mode and +/- 4Mbytes in Thumb mode.)
解決方法:
對于C文件來說,編譯選項CFLAGS加入'-mlong-calls'選項;
對匯編文件來說,使用如下的跳轉指令
ldr r4, =func
mov lr, pc
bx r4