Link error when sprintf() used

Asked by Mirek

Greetings,
I'm trying to get compiler working with C::B. Compiler's instalator: gcc-arm-none-eabi-4_6-2012q2-20120614.exe
<stdlib.h> atoi(), <string.h> strchr(), strcpy() causes no problems.
That's not the case of <stdio.h> sprintf().
=== build log ====
Linking console executable: bin\Debug\test.elf
C:\GNU ARM Emb\lib\gcc\arm-none-eabi\4.6.2\libgcc.a(unwind-arm.o): In function `get_eit_entry':
unwind-arm.c:(.text+0x200): undefined reference to `__exidx_start'
unwind-arm.c:(.text+0x204): undefined reference to `__exidx_end'
C:\GNU ARM Emb\lib\gcc\arm-none-eabi\4.6.2\libgcc.a(unwind-arm.o): In function `unwind_phase2':
unwind-arm.c:(.text+0x41c): undefined reference to `abort'
C:\GNU ARM Emb\lib\gcc\arm-none-eabi\4.6.2\libgcc.a(unwind-arm.o): In function `__gnu_Unwind_Resume':
unwind-arm.c:(.text+0xd88): undefined reference to `abort'
unwind-arm.c:(.text+0xdb4): undefined reference to `abort'
C:\GNU ARM Emb\lib\gcc\arm-none-eabi\4.6.2\libgcc.a(pr-support.o): In function `_Unwind_GetDataRelBase':
pr-support.c:(.text+0x54c): undefined reference to `abort'
C:\GNU ARM Emb\lib\gcc\arm-none-eabi\4.6.2\libgcc.a(pr-support.o): In function `_Unwind_GetTextRelBase':
pr-support.c:(.text+0x554): undefined reference to `abort'
C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk'
====

Translation passes if I add void functions named like undefined references in build log. Same effect can be achieved adding so named sections into linker script.
I'm sure it isn't correct solution of problem. What could cause this?

Thanks fo your time.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
chengbin
Solved:
Last query:
Last reply:
Revision history for this message
chengbin (can-finner) said :
#1

Hi Mirek,
Glad to hear that you are trying to integrate our tool in another IDE.
I have no experience with C::B, so can't tell what's going on with minimal information. I suggest that you build the example project in command line, see whether the problem exists. If not, please verify the difference between command line build and IDE build, for example, the options generated/passed by IDE. If yes, could you post an example and corresponding command line options here?

Thanks

Revision history for this message
Mirek (dr-bambus) said :
#2

Source files are compiled by command:
arm-none-eabi-gcc.exe -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -g -mthumb -Os -Wall -mcpu=cortex-m3 -ffunction-sections -fdata-sections -Isrc -ILibraries\CMSIS\CM3\CoreSupport -ILibraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x -ILibraries\STM32F10x_StdPeriph_Driver\inc -c src\main.c -o obj\Debug\src\main.o

There is also one asm file:
arm-none-eabi-g++.exe -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -g -mthumb -Os -Wall -mcpu=cortex-m3 -ffunction-sections -fdata-sections -Isrc -ILibraries\CMSIS\CM3\CoreSupport -ILibraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x -ILibraries\STM32F10x_StdPeriph_Driver\inc -c Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\TrueSTUDIO\startup_stm32f10x_md.s -o obj\Debug\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\TrueSTUDIO\startup_stm32f10x_md.o

Linking is done by:
arm-none-eabi-ld.exe -o bin\Debug\tPortBlink.elf obj\Debug\Libraries\CMSIS\CM3\CoreSupport\core_cm3.o //... many other .o files ...// obj\Debug\src\delay.o obj\Debug\src\main.o obj\Debug\src\systick.o -Tstm32_lscr.ld -Map=bin\Debug\tPortBlink.map -L"C:\GNU ARM Emb\arm-none-eabi\lib" -L"C:\GNU ARM Emb\lib\gcc\arm-none-eabi\4.6.2" -cref --gc-sections

when I look at .map file and compare it with error message:
===== error
C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk'
=====
it contains records:
===== .map
_sbrk C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o)
_sbrk_r C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o)

.text._sbrk_r 0x08008274 0x40 C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o)
                0x08008274 _sbrk_r
=====
but no similar definition of "_sbrk".

Translation from command line will take some time. I have to learn how to create makefile first.

Revision history for this message
Joey Ye (jinyun-ye) said :
#3

Does your program use 64-bit division operation?
On Sep 27, 2012 9:31 PM, "Mirek" <email address hidden>
wrote:

> Question #209628 on GCC ARM Embedded changed:
> https://answers.launchpad.net/gcc-arm-embedded/+question/209628
>
> Status: Needs information => Open
>
> Mirek gave more information on the question:
> Source files are compiled by command:
> arm-none-eabi-gcc.exe -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -g -mthumb -Os
> -Wall -mcpu=cortex-m3 -ffunction-sections -fdata-sections -Isrc
> -ILibraries\CMSIS\CM3\CoreSupport
> -ILibraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x
> -ILibraries\STM32F10x_StdPeriph_Driver\inc -c src\main.c -o
> obj\Debug\src\main.o
>
> There is also one asm file:
> arm-none-eabi-g++.exe -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -g -mthumb -Os
> -Wall -mcpu=cortex-m3 -ffunction-sections -fdata-sections -Isrc
> -ILibraries\CMSIS\CM3\CoreSupport
> -ILibraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x
> -ILibraries\STM32F10x_StdPeriph_Driver\inc -c
> Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\TrueSTUDIO\startup_stm32f10x_md.s
> -o
> obj\Debug\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\TrueSTUDIO\startup_stm32f10x_md.o
>
> Linking is done by:
> arm-none-eabi-ld.exe -o bin\Debug\tPortBlink.elf
> obj\Debug\Libraries\CMSIS\CM3\CoreSupport\core_cm3.o //... many other .o
> files ...// obj\Debug\src\delay.o obj\Debug\src\main.o
> obj\Debug\src\systick.o -Tstm32_lscr.ld -Map=bin\Debug\tPortBlink.map
> -L"C:\GNU ARM Emb\arm-none-eabi\lib" -L"C:\GNU ARM
> Emb\lib\gcc\arm-none-eabi\4.6.2" -cref --gc-sections
>
>
> when I look at .map file and compare it with error message:
> ===== error
> C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o): In function
> `_sbrk_r':
> sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk'
> =====
> it contains records:
> ===== .map
> _sbrk C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o)
> _sbrk_r C:\GNU ARM Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o)
>
> .text._sbrk_r 0x08008274 0x40 C:\GNU ARM
> Emb\arm-none-eabi\lib\libc.a(lib_a-sbrkr.o)
> 0x08008274 _sbrk_r
> =====
> but no similar definition of "_sbrk".
>
>
> Translation from command line will take some time. I have to learn how to
> create makefile first.
>
> --
> You received this question notification because you are an answer
> contact for GCC ARM Embedded.
>

Revision history for this message
Mirek (dr-bambus) said :
#4

No, it is simple led blinking demo with use of sprintf(str, "%d.%d.%d.%d", 4x uint8_t var).

Revision history for this message
Best chengbin (can-finner) said :
#5

Apart from standard libc.a, you have to link libnosys.a or librdimon.a which provide syscalls including _sbrk.
Also it would be better to call arm-non-eabi-gcc as linking wrapper, rather than arm-none-eabi-ld directly.
Please refer to Readme.txt for some information on this.

Hoping this help.

Revision history for this message
Mirek (dr-bambus) said :
#6

Great thanks!
Translation works with linker script modified according to example in readme file (loaded libnosys.a and defined some sections). Tomorrow i'll test it on hw.
There are several sections which "code can use without definition", but not all of them are defined in example script. Is there available detailed description of these sections somewhere (maybe on arm site linked in readme which requires registration )?

Revision history for this message
Mirek (dr-bambus) said :
#7

Thanks chengbin, that solved my question.