Hi everyone,
im using "toolchain
-bu-2.15_gcc-3.4.3-c-c++-java_nl-1.12.0_gi-6.1.tar.bz2" to compile a simple program for an ARM920T based microcontroller (AT91RM9200). The development system is running Fedora Core 3.
i have not been able to use the "sprintf" function..the program does not compile if i do so. here are the details of my problem:
************************************************************code snippet of my main.c program (where im calling sprintf):
============================== #include . sprintf( buf, "This is a test %d one and %d two", 420, 840 ); .==============================
This is the error i get:
============================== . arm-elf-gcc -c -Os -DAT91RM9200 -mlittle-endian -mapcs-32 -mcpu=arm920t
-fno-inline -o "init.o" "init.c" arm-elf-gcc -c -Os -DAT91RM9200 -mlittle-endian -mapcs-32 -mcpu=arm920t
-fno-inline -o "main.o" "main.c" arm-elf-ld -L --cref -Map BasicBoot.map -EL -T./ld_mk.script -o "./Mayank/Output/BasicBootDebug.elf" cstartup.o init.o main.o init.o(.text+0x100): In function `AT91F_US_Baudrate': : undefined reference to `__udivsi3' init.o(.text+0x10c): In function `AT91F_US_Baudrate': : undefined reference to `__umodsi3' init.o(.text+0x120): In function `AT91F_US_Baudrate': : undefined reference to `__udivsi3' init.o(.text+0x134): In function `AT91F_US_Baudrate': : undefined reference to `__udivsi3' init.o(.text+0x26c): In function `AT91F_CheckPLL_FrequencyRange': : undefined reference to `__divsi3' main.o(.text+0x60): In function `main': : undefined reference to `sprintf' make: *** [Mayank/Output/BasicBootDebug.elf] Error 1 ==============================
I had searched the net and found that undefined references to `__divsi3` and `__umodsi3' are caused because of problems or version mismatches related to libgcc.a . Heres my linker script:
============================== GROUP("/home/guest/mayank_arm/gnuarm-3.4.3/arm-elf/lib/libc.a" "/home/guest/mayank_arm/gnuarm-3.4.3/lib/gcc/arm-elf/3.4.3/libgcc.a")
MEMORY { ram : ORIGIN = 0x200000, LENGTH = 0x3000 /*12kb*/ }
SECTIONS {
.text : { __stext_start = . ; /*Start of the text section*/ *(.text) *(.rodata.*) . = ALIGN(4); __stext_end = . ; /*End of the text section*/ } > ram
.data : {
__sdata_start = . ; /*Start of the data section*/ *(.data) *(.glue_7*) *(.stack) *(.*) . = ALIGN(4); __sdata_end = . ; /*End of the data section*/ } > ram
.bss : { __sbss_start = . ; /*Start of the bss section*/ *(.bss) . = ALIGN(4); __sbss_end = . ; /*End of the bss section*/ } > ram } ==============================
This is how the liker is being called in my Makefile:
============================== LINK=arm-elf-ld -L --cref -Map BasicBoot.map -EL -T./ld_mk.script -o "$(OUTDIR)/$(OUTFILE)" $(OBJ) ==============================
******************************************************* (I have checked these archives im using, by issuing the command "nm -sC libc.a|grep sprintf" and libgcc.a for __umodsi3, they were shown to be present inside their respective files.)I tried another approach: i commented out the GROUP() in the linker script, changed the linker invocation in the Makefile to this:
============================== CFG_LIB2='/home/guest/mayank_arm/gnuarm-3.4.3/arm-elf/lib/libc.a' CFG_LIB1='/home/guest/mayank_arm/gnuarm-3.4.3/lib/gcc/arm-elf/3.4.3/libgcc.a'
LINK=arm-elf-ld --cref -Map BasicBoot.map -EL -T./ld_mk.script -o "$(OUTDIR)/$(OUTFILE)" $(OBJ) --start-group $(CFG_LIB2) $(CFG_LIB1)
--end-group ==============================
These are the errors i get: ============================== arm-elf-gcc -c -Os -DAT91RM9200 -mlittle-endian -mapcs-32 -mcpu=arm920t
-fno-inline -o "init.o" "init.c" arm-elf-gcc -c -Os -DAT91RM9200 -mlittle-endian -mapcs-32 -mcpu=arm920t
-fno-inline -o "main.o" "main.c" arm-elf-ld --cref -Map BasicBoot.map -EL -T./ld_mk.script -o "./Mayank/Output/BasicBootDebug.elf" cstartup.o init.o main.o
--start-group '/home/guest/mayank_arm/gnuarm-3.4.3/arm-elf/lib/libc.a' '/home/guest/mayank_arm/gnuarm-3.4.3/lib/gcc/arm-elf/3.4.3/libgcc.a'
--end-group arm-elf-ld: region ram is full (./Mayank/Output/BasicBootDebug.elf section .text) arm-elf-ld: region ram is full (./Mayank/Output/BasicBootDebug.elf section .data) arm-elf-ld: section .data [00200000 -> 00221fd7] overlaps section .text [00200000 -> 002084a3] arm-elf-ld: section .bss [00200000 -> 00200003] overlaps section .text [00200000 -> 002084a3] /home/guest/mayank_arm/gnuarm-3.4.3/arm-elf/lib/libc.a(syscalls.o)(.text+0x69c): In function `_sbrk': ../../../../../../newlib-1.12.0/newlib/libc/sys/arm/syscalls.c:508: undefined reference to `end' make: *** [Mayank/Output/BasicBootDebug.elf] Error 1 ==============================
Please note that this particular program had originally been built for Arm Developer Suite 1.2, and the size of the compiled code was 5k only. I have made the requisite changes for it to work with GNU tools.
Where am i going wrong ?!
Thanx in anticipation, Mayank