Page 1 of 1

undefined reference error while compiling binutils

Posted: Wed Mar 07, 2012 11:46 pm
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

Re: undefined reference error while compiling binutils

Posted: Thu Mar 08, 2012 5:19 am
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)"

Re: undefined reference error while compiling binutils

Posted: Thu Mar 08, 2012 5:32 am
by ammubhave
yes it is

Re: undefined reference error while compiling binutils

Posted: Thu Mar 08, 2012 5:44 am
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 ?

Re: undefined reference error while compiling binutils

Posted: Thu Mar 08, 2012 5:48 am
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.

Re: undefined reference error while compiling binutils

Posted: Fri Mar 09, 2012 5:42 am
by ammubhave
some one?

Re: undefined reference error while compiling binutils

Posted: Fri Mar 09, 2012 5:43 am
by Solar
Cannot reproduce...