newli link problem

OP #1173178
Hi,

I am new to both gnuarm and newlib. I download the toolchain provided by
Darrik Spaude from gnuarm.org, and I am trying to build my
hello_world.c, but I got the following error:

/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-freer.o):
In function `_malloc_trim_r':
../../../.././newlib/libc/stdlib/mallocr.c:3326: undefined reference to
`_sbrk_r'
../../../.././newlib/libc/stdlib/mallocr.c:3335: undefined reference to
`_sbrk_r'
../../../.././newlib/libc/stdlib/mallocr.c:3340: undefined reference to
`_sbrk_r'
/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-makebuf.o):
In function `__smakebuf':
../../../.././newlib/libc/stdio/makebuf.c:54: undefined reference to
`_fstat_r'
/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-mallocr.o):
In function `malloc_extend_top':
../../../.././newlib/libc/stdlib/mallocr.c:2160: undefined reference to
`_sbrk_r'
../../../.././newlib/libc/stdlib/mallocr.c:2197: undefined reference to
`_sbrk_r'
/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-stdio.o):
In function `__sclose':
../../../.././newlib/libc/stdio/stdio.c:120: undefined reference to
`_close_r'
/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-stdio.o):
In function `__sseek':
../../../.././newlib/libc/stdio/stdio.c:103: undefined reference to
`_lseek_r'
/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-stdio.o):
In function `__swrite':
../../../.././newlib/libc/stdio/stdio.c:76: undefined reference to
`_lseek_r'
../../../.././newlib/libc/stdio/stdio.c:84: undefined reference to
`_write_r'
/usr/local/arm/bin/../lib/gcc/arm-elf/4.2.0/../../../../arm-elf/lib/libc 
.a(lib_a-stdio.o):
In function `__sread':
../../../.././newlib/libc/stdio/stdio.c:47: undefined reference to
`_read_r'

I searched the web, and I think this is caused by missing stub
implementations. My host machine is Intel MAC and the target is
At91sam9260 based board running linux 2.6.22.1. I found that in the
toolchain it already contians a libgloss-linux.a, then I tried to
compile with -lgloss-linux,but I got the same error.

Is there an available newlib stub implementation for arm-linux? Or maybe
I misused the libgloss-linux.a?

I checked with: arm-elf-nm libgloss-linux.a|grep sbrk
000000ac T _sbrk
000000ac T sbrk
it seems the _sbrk_r is missing.
#1173179
Thanks for posting here, Fan. I was going to do the same.

Any suggestions are greatly appreciated. I have a request to GNUARM
about the same issue and will post back here if I find any solution. If
I find a solution, then I will also generate a new toolchain.

Darrik
OP #1173180
Darrik Spaude wrote:
> Thanks for posting here, Fan. I was going to do the same.
>
> Any suggestions are greatly appreciated. I have a request to GNUARM
> about the same issue and will post back here if I find any solution. If
> I find a solution, then I will also generate a new toolchain.
>
> Darrik

Thanks for the quick reply. I really appreciate for your contribution
about GNUARM. :)
#1173181
Just to follow up, the Mac versions of the toolchain I built include
reentrancy, so the undefined references in question need to be defined
by the source being compiled and linked. For example, in an embedded
system a printf() could mean output is sent to a UART or USB or some
other device, so the implementation needs to define which device is the
default target for a write.

Thanks goes to Pablo at GNU ARM for his input.

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.