Undefined reference to strlen, although library is supplied
Hermann-Simon Lichte
gem@upb.de
Mon Feb 9 12:45:00 GMT 2004
Hello everybody,
first, I'd like to thank everyone who responded to my first mail
concerning the powerpc-eabi compiler build. Especially, I found Kai's
hints the most productive ones, and by taking his steps into
consideration, the build was just a piece of cake.
I am now trying to build a simple C++ application with my powerpc-eabi
compiler. I have written an appropriate linker configuration file that
fits my target development board (a Phytec phyCORE-MPC555 hooked up
using the Wiggler interface, just in case one likes to know).
The final link fails due to an undefined reference to strlen. However,
this function is present in libc.a, and even though I tell the linker to
use libc.a, it keeps complaining. An objdump reveals its presence, the
linker flags seem fine to me, so how come it doesn't link properly?
I tried to build my application earlier with success by using a
pre-defined architecture (such as ads, yellowknife etc.) Then, the
linking stage finishes properly. Now, I want to leave out the -mads
option. I created a system.o file that contains the required system
functions (_exit, sbrk, getpid, and kill) with a minimal implementation
similar to those suggested in the Newlib documentation.
To make things a little clearer, here are the error messages and some dumps:
$ make all
powerpc-eabi-gcc -mcpu=505 -c src/system.c -o src/system.o
powerpc-eabi-gcc -mcpu=505 -c src/main.cc -o src/main.o
powerpc-eabi-gcc -mcpu=505 -c src/LED.cc -o src/LED.o
powerpc-eabi-gcc -T phycore555.ld -o build/blinky++.elf src/system.o
src/LED.o src/main.o -lstdc++ -lg -lc
/usr/local/lib/gcc-lib/powerpc-eabi/3.3.2/../../../../powerpc-eabi/bin/ld:
warning: cannot find entry symbol _start; defaulting to 00802000
/usr/local/lib/gcc-lib/powerpc-eabi/3.3.2/libgcc.a(unwind-dw2.o)(.text+0x3e4):
In function `extract_cie_info':
/home/gem/crossgcc/gcc-3.3.2/gcc/unwind-dw2.c:247: undefined reference
to `strlen'
/usr/local/lib/gcc-lib/powerpc-eabi/3.3.2/libgcc.a(unwind-dw2.o)(.text+0xd08):
In function `execute_cfa_program':
/home/gem/crossgcc/gcc-3.3.2/gcc/unwind-dw2.c:820: undefined reference
to `memcpy'
----(Snip)----------------------------------------------------------------------
powerpc-eabi-nm tells me that strlen as well as memcpy are defined.
An objdump of libc.a also shows me their presences.
$ powerpc-eabi-objdump -d -X `powerpc-eabi-gcc -print-file-name=libc.a`
----(Snip)----------------------------------------------------------------------
strlen.o: file format elf32-powerpc
rw-r--r-- 16162/22680 7244 Feb 6 10:26 2004 strlen.o
architecture: powerpc:common, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000
....
Disassembly of section .text:
00000000 <strlen>:
0: 70 60 00 03 andi. r0,r3,3
4: 94 21 ff e0 stwu r1,-32(r1)
8: 7c 6a 1b 78 mr r10,r3
c: 40 82 00 44 bne- 50 <strlen+0x50>
----(Snip)----------------------------------------------------------------------
I don't understand why the linker doesn't resolve the references. Maybe
I am still not supplying the right flags to it, but maybe it's a totally
different problem that I am not yet aware about. What also bothers me is
that by supplying -mads (or -myellowknife) to the linker (without my
system.o) the linking stage succeeds. It seems likely to me that there
are still things left to consider.
If I am not totally mislead, I believe that, in addition, I still need
to write startup code for my target. By leaving out -mads it is not
using any crt0, is it? What does actually need to be done in crt0? Is it
sufficient to just set up the initial stack frame? To make global
variables work, specific processor registers also need to be set up, as
far as I know (I think they are R2, table of contents, and R13, global
data, but I will do more research on that). What else needs to be
included in a typical crt0 for an embedded target such as mine?
----(Snip)----------------------------------------------------------------------
/usr/local/lib/gcc-lib/powerpc-eabi/3.3.2/libgcc.a(eabi.o)(.text+0xc4):
In function `__eabi':
/home/gem/crossgcc/build-gcc/gcc/eabi.S:232: undefined reference to `__init'
----(Snip)----------------------------------------------------------------------
Anyway, IMHO, a missing crt0 does not explain the unresolved strlen and
memcpy references. There must be another reason for that.
I am about to dig a littler deeper into the predefined libglosses
(reading sources). I am still new to embedded development, and this is a
very nice adventure trip for me.
So this is why I am asking kindly for another push into the right
direction. Such a discussion on the mailing list might also be helpful
for others digging into this subject as well.
Thank you all.
Hermann
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com
More information about the crossgcc
mailing list