undefined reference error while compiling binutils

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ammubhave
Posts: 11
Joined: Tue Jun 07, 2011 8:17 am

undefined reference error while compiling binutils

Post by ammubhave »

Hi, I am making my os specific toolchain and the first step is to build binutils. I followed all the steps regarding binutils given in http://wiki.osdev.org/OS_Specific_Toolchain and did a make. Everything goes right but when it comes to making ld the following error pops up:
(btw my os name is AmolOs, target is i586_pc_amolos, emulation name is amolos_i386: from the steps given in the wiki)

make[4]: Entering directory `/usr/src/build-binutils/ld'
/bin/sh ./libtool --tag=CC --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -Wl,--stack,12582912 -o ld-new.exe ldgram.o ldlex-wrapper.o lexsup.o ldlang.o mri.o ldctor.o ldmain.o ldwrite.o ldexp.o ldemul.o ldver.o ldmisc.o ldfile.o ldcref.o plugin.o eamolos_i386.o ../bfd/libbfd.la ../libiberty/libiberty.a -lz
libtool: link: gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -Wl,--stack -Wl,12582912 -o .libs/ld-new.exe ldgram.o ldlex-wrapper.o lexsup.o ldlang.o mri.o ldctor.o ldmain.o ldwrite.o ldexp.o ldemul.o ldver.o ldmisc.o ldfile.o ldcref.o plugin.o eamolos_i386.o ../bfd/.libs/libbfd.a ../libiberty/libiberty.a -lz
ldemul.o: In function `ldemul_hll':
/usr/src/build-binutils/ld/../../binutils-2.22/ld/ldemul.c:41: undefined reference to `_ld_amolos_i386_emulation'

collect2: ld returned 1 exit status
Makefile:1033: recipe for target `ld-new.exe' failed
make[4]: *** [ld-new.exe] Error 1
make[4]: Leaving directory `/usr/src/build-binutils/ld'
Makefile:1643: recipe for target `all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/usr/src/build-binutils/ld'
Makefile:911: recipe for target `all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory `/usr/src/build-binutils/ld'
Makefile:7015: recipe for target `all-ld' failed
make[1]: *** [all-ld] Error 2
make[1]: Leaving directory `/usr/src/build-binutils'
Makefile:842: recipe for target `all' failed
make: *** [all] Error 2

I am pretty sure that I have followed all the steps carefully.

amolos_i386.sh

Code: Select all

ARCH=i386
SCRIPT_NAME=pe
OUTPUT_FORMAT="pei-i386"
RELOCATEABLE_OUTPUT_FORMAT="pe-i386"
TEMPLATE_NAME=pe
SUBSYSTEM=PE_DEF_SUBSYSTEM
INITIAL_SYMBOL_CHAR=\"_\"
TARGET_PAGE_SIZE=0x1000
GENERATE_AUTO_IMPORT_SCRIPT=1
extract from Makefile.in (of ld directory)

Code: Select all

...
eamolos_i386.c: $(srcdir)/emulparams/amolos_i386.sh \
  $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
	${GENSCRIPTS} amolos_i386 "$(tdir_amolos_i386)"
...
extract from configure.tgt

Code: Select all

i[3-7]86-*-amolos*)	targ_emul=amolos_i386
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: undefined reference error while compiling binutils

Post by gerryg400 »

Is this bit coded as a proper Makefile rule, with a tab character in the beginning of the 3rd line ?

Code: Select all

eamolos_i386.c: $(srcdir)/emulparams/amolos_i386.sh \
  $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
   ${GENSCRIPTS} amolos_i386 "$(tdir_amolos_i386)"
If a trainstation is where trains stop, what is a workstation ?
ammubhave
Posts: 11
Joined: Tue Jun 07, 2011 8:17 am

Re: undefined reference error while compiling binutils

Post by ammubhave »

yes it is
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: undefined reference error while compiling binutils

Post by gerryg400 »

Do you have a file called ldemul-list.h ? It should be in binutils-build/ld directory. It should contain an extern for each of the emulations like this

Code: Select all

extern ld_emulation_xfer_type ld_elf_x86_64_emulation;
extern ld_emulation_xfer_type ld_elf_i386_emulation;
extern ld_emulation_xfer_type ld_elf_l1om_emulation;
extern ld_emulation_xfer_type ld_elf_k1om_emulation;

#define EMULATION_LIST \
  &ld_elf_x86_64_emulation, \
  &ld_elf_i386_emulation, \
  &ld_elf_l1om_emulation, \
  &ld_elf_k1om_emulation, \
  0
Then there should be a c file for each emulation also in binutils-build/ld. One of them should be for your OS but there should be 4 or 5 of them. They are generated by scripts. Do you have those ?
If a trainstation is where trains stop, what is a workstation ?
ammubhave
Posts: 11
Joined: Tue Jun 07, 2011 8:17 am

Re: undefined reference error while compiling binutils

Post by ammubhave »

the ldemul-list.h contains:

Code: Select all

/* This file is automatically generated.  DO NOT EDIT! */
extern ld_emulation_xfer_type ld_amolos_i386_emulation;

#define EMULATION_LIST \
  &ld_amolos_i386_emulation, \
  0
And there is a file eamolos_i386.c in build-binutils/ld but that file is empty.
ammubhave
Posts: 11
Joined: Tue Jun 07, 2011 8:17 am

Re: undefined reference error while compiling binutils

Post by ammubhave »

some one?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: undefined reference error while compiling binutils

Post by Solar »

Cannot reproduce...
Every good solution is obvious once you've found it.
Post Reply