LD undefined reference to existing symbol

b.zaar billy.zaar@gmail.com
Tue Jan 11 09:50:00 GMT 2011


Hi, I'm using a cross compiler for i386-elf to develop a boot loader. I'm
using the gcc tools under cygwin if that might make a difference. The
problem is an undefined reference to an existing symbol. The code is
compiled with nasm and then linked with gnu ld. I'm finding ld wont link
with more than 5 global symbols defined in the nasm elf object file. This is
the output from the link command.

$ i386-elf-ld.exe -y print -y printhex -Map loader.map -T
../../src/boot/loader
.ld start.o pmi.o cpuid.o main.o int.o -o loader
start.o: definition of printhex
start.o: definition of print
pmi.o: reference to print
pmi.o: reference to printhex
pmi.o: In function `initpmi':
/usr/src/venom-os/src/boot/pmi.s:(.text16+0x6): undefined reference to
`print'
pmi.o: In function `pmdie.skip':
/usr/src/venom-os/src/boot/pmi.s:(.text16+0x64): undefined reference to
`print'
/usr/src/venom-os/src/boot/pmi.s:(.text16+0x6): undefined reference to
`print'
pmi.o: In function `pmdie.skip':
/usr/src/venom-os/src/boot/pmi.s:(.text16+0x64): undefined reference to
`print'


If I rearrange the source code to have the print label/proc appear before
printhex I get the following output.

$ i386-elf-ld.exe -y print -y printhex -Map loader.map -T
../../src/boot/loader
.ld start.o pmi.o cpuid.o main.o int.o -o loader
start.o: definition of print
start.o: definition of printhex
pmi.o: reference to print
pmi.o: reference to printhex
pmi.o: In function `pmdie':
/usr/src/venom-os/src/boot/pmi.s:(.text16+0x5e): undefined reference to
`printhex'


So there must be something about the ordering or limit of global/extern
symbols that ld is working with. The version of nasm is: NASM version
2.08.02 compiled on Jul 12 2010
and ld's version: GNU ld (GNU Binutils) 2.20.51.20100410

I can see the objects defined as globals in the nasm elf object file for
start.o using objdump -t so they seemed to be defined correctly.

Any help would be appreciated, thanks.
-- 
View this message in context: http://old.nabble.com/LD-undefined-reference-to-existing-symbol-tp30641987p30641987.html
Sent from the gcc - Help mailing list archive at Nabble.com.



More information about the Gcc-help mailing list