Page 1 of 1

Cross-Compiling, Boomstick Target

Posted: Fri Nov 23, 2012 5:17 pm
by Geometrian
Hi,

I've been working a lot, but I still haven't gotten a kernel to load from my bootloader (which I rewrote). The issue right now is that I can't compile a flat binary for the second-stage bootloader/kernel. Host system is x86-64 Windows 7, using Cygwin.

I have read through the BabySteps tutorials, and am now working on implementing from the C Bare Bones tutorial, but I got stuck when trying to link my second stage bootloader with my basic kernel. I get:

Code: Select all

ld.exe: bootloader2.o: Relocations in generic ELF (EM: 3)
Some Googling didn't turn up anything relevant, so I decided to actually set up a cross-compiler as recommended. In all honesty though, I don't understand how it differs so greatly from an ordinary compiler.

After reviewing the cross-compiler page, I found Boomstick, which appears to automate the process. I had to change the build.sh substantially (some of the packages aren't at their old locations), so I updated all the URLs and removed the old patches. The result is the following, which may, (if what I did makes sense) be of some use:

Code: Select all

OSNAME=myos

BINUTILS_VER=2.23.1
GCC_VER=4.6.3
GMP_VER=5.0.2
MPFR_VER=3.1.1
NEWLIB_VER=1.20.0
MPC_VER=0.8.1

export TARGET=x86_64-pc-${OSNAME}
export PREFIX=`pwd`/local

mkdir -p build
mkdir -p local
cd build

WFLAGS=-c

export PATH=$PREFIX/bin:$PATH

# Fetch each package

echo "FETCH BINUTILS"
wget $WFLAGS http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.gz 
tar -xf binutils-${BINUTILS_VER}.tar.gz

echo "FETCH GCC"
wget $WFLAGS http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-core-${GCC_VER}.tar.gz
tar -xf gcc-core-${GCC_VER}.tar.gz
wget $WFLAGS http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-g++-${GCC_VER}.tar.gz
tar -xf gcc-g++-${GCC_VER}.tar.gz
wget $WFLAGS http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-fortran-${GCC_VER}.tar.gz
tar -xf gcc-fortran-${GCC_VER}.tar.gz

echo "FETCH GMP"
wget $WFLAGS http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VER}.tar.gz
tar -xf gmp-${GMP_VER}.tar.gz

echo "FETCH MPFR"
wget $WFLAGS http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VER}.tar.gz
tar -xf mpfr-${MPFR_VER}.tar.gz

echo "FETCH MPC"
wget $WFLAGS http://www.multiprecision.org/mpc/download/mpc-${MPC_VER}.tar.gz
tar -xf mpc-${MPC_VER}.tar.gz

echo "FETCH NEWLIB"
wget $WFLAGS ftp://sources.redhat.com/pub/newlib/newlib-${NEWLIB_VER}.tar.gz
tar -xf newlib-${NEWLIB_VER}.tar.gz

# Push new code into each package

echo "MAKE OBJECT DIRECTORIES"
mkdir -p binutils-obj
mkdir -p gcc-obj
mkdir -p newlib-obj
mkdir -p gmp-obj
mkdir -p mpfr-obj
mkdir -p mpc-obj

# Compile all packages

echo "COMPILE BINUTILS"
cd binutils-obj
../binutils-${BINUTILS_VER}/configure --target=$TARGET --prefix=$PREFIX --disable-werror || exit
make || exit
make install || exit
cd ..

echo "COMPILE GMP"
cd gmp-obj
../gmp-${GMP_VER}/configure --prefix=$PREFIX --disable-shared || exit
make || exit
make check || exit
make install || exit
cd ..

echo "COMPILE MPFR"
cd mpfr-obj
../mpfr-${MPFR_VER}/configure --prefix=$PREFIX --with-gmp=$PREFIX --disable-shared
make || exit
make check || exit
make install || exit
cd ..

echo "COMPILE MPC"
cd mpc-obj
../mpc-${MPC_VER}/configure --target=$TARGET --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX --disable-shared || exit
make || exit
make check || exit
make install || exit
cd ..


echo "AUTOCONF GCC"
cd gcc-${GCC_VER}/libstdc++-v3
#autoconf || exit
cd ../..

echo "COMPILE GCC"
cd gcc-obj
../gcc-${GCC_VER}/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++,fortran --disable-libssp --with-gmp=$PREFIX --with-mpfr=$PREFIX --with-mpc=$PREFIX --disable-nls --with-newlib || exit

make all-gcc || exit
make install-gcc || exit
cd ..

echo "AUTOCONF NEWLIB"
cd newlib-${NEWLIB_VER}/newlib/libc/sys
autoconf || exit
cd ${OSNAME}
autoreconf || exit
cd ../../../../..

echo "CONFIGURE NEWLIB"
cd newlib-obj
../newlib-${NEWLIB_VER}/configure --target=$TARGET --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX || exit

echo "COMPILE NEWLIB"
make || exit
make install || exit
cd ..

echo "PASS-2 COMPILE GCC"
cd gcc-obj
#make all-target-libgcc
#make install-target-libgcc
make all-target-libstdc++-v3 || exit
make install-target-libstdc++-v3 || exit
make || exit
make install || exit
cd ..

echo "PASS-2 COMPILE NEWLIB"
cp ../newlib-files/syscalls.c newlib-${NEWLIB_VER}/newlib/libc/sys/${OSNAME}/syscalls.c

cd newlib-obj
#../newlib-${NEWLIB_VER}/configure --target=$TARGET --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX || exit
make || exit
make install || exit
cd ..
The problem is that after a certain amount through, it will print this:

Code: Select all

COMPILE BINUTILS
checking build system type... i686-pc-cygwin
checking host system type... i686-pc-cygwin
checking target system type... Invalid configuration `x86_64-pc-myos': system `myos' not recognized
configure: error: /bin/sh ../binutils-2.23.1/config.sub x86_64-pc-myos failed
What the right thing intended here was I knew even less than usual, so I didn't guess.

Can someone please explain what the --target parameter of configure in Boomstick was supposed to be? And possibly also why Cygwin's default ld didn't work?

Thanks,

Re: Cross-Compiling, Boomstick Target

Posted: Fri Nov 23, 2012 5:56 pm
by JackScott
For a kernel such as yours, which doesn't have a C runtime or library of it's own yet, you'll want to use one of the 'bare' GCC configurations, without any system specifics at all. Recommended targets are 'i586-elf' and 'x86_64-elf'. This should get you a working cross-compiler like that from the tutorial.

So use:

Code: Select all

export TARGET=i586-elf

Re: Cross-Compiling, Boomstick Target

Posted: Fri Nov 23, 2012 11:06 pm
by Geometrian
Attempting the above allows compilation to proceed further. It still fails when compiling binutils--the first sign of trouble in the compilation, other than some warnings--with the following:

Code: Select all

gcc -c -DHAVE_CONFIG_H -g -O2  -I. -I../../binutils-2.23.1/libiberty/../include  -W -Wall -Wwrite-strings -Wc++-compat                                                    -Wstrict-prototypes -pedantic  ../../binutils-2.23.1/libiberty/pex-unix.c -o pex-unix.o
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'pex_wait':
../../binutils-2.23.1/libiberty/pex-unix.c:256: warning: implicit declaration of function 'wait'
../../binutils-2.23.1/libiberty/pex-unix.c: At top level:
../../binutils-2.23.1/libiberty/pex-unix.c:325: warning: initialization from incompatible pointer type
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'save_and_install_fd':
../../binutils-2.23.1/libiberty/pex-unix.c:407: warning: implicit declaration of function 'fcntl'
../../binutils-2.23.1/libiberty/pex-unix.c:407: error: 'F_GETFD' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c:407: error: (Each undeclared identifier is reported only once
../../binutils-2.23.1/libiberty/pex-unix.c:407: error: for each function it appears in.)
../../binutils-2.23.1/libiberty/pex-unix.c:420: error: 'FD_CLOEXEC' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c:420: error: 'F_SETFD' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c:433: error: 'F_DUPFD' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'restore_fd':
../../binutils-2.23.1/libiberty/pex-unix.c:467: error: 'FD_CLOEXEC' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c:469: error: 'F_SETFD' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'pex_unix_exec_child':
../../binutils-2.23.1/libiberty/pex-unix.c:551: warning: passing argument 3 of 'spawnvpe' from incompatible pointer type
c:\dev\perl\c\bin\../lib/gcc/x86_64-w64-mingw32/4.4.3/../../../../x86_64-w64-mingw32/include/process.h:169: note: expected 'char * const*' but argument is of type 'const char * const*'
../../binutils-2.23.1/libiberty/pex-unix.c:551: warning: passing argument 4 of 'spawnvpe' from incompatible pointer type
c:\dev\perl\c\bin\../lib/gcc/x86_64-w64-mingw32/4.4.3/../../../../x86_64-w64-mingw32/include/process.h:169: note: expected 'char * const*' but argument is of type 'const char * const*'
../../binutils-2.23.1/libiberty/pex-unix.c:553: warning: passing argument 3 of 'spawnve' from incompatible pointer type
c:\dev\perl\c\bin\../lib/gcc/x86_64-w64-mingw32/4.4.3/../../../../x86_64-w64-mingw32/include/process.h:167: note: expected 'char * const*' but argument is of type 'const char * const*'
../../binutils-2.23.1/libiberty/pex-unix.c:553: warning: passing argument 4 of 'spawnve' from incompatible pointer type
c:\dev\perl\c\bin\../lib/gcc/x86_64-w64-mingw32/4.4.3/../../../../x86_64-w64-mingw32/include/process.h:167: note: expected 'char * const*' but argument is of type 'const char * const*'
../../binutils-2.23.1/libiberty/pex-unix.c:562: warning: implicit declaration of function 'sleep'
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'pex_unix_wait':
../../binutils-2.23.1/libiberty/pex-unix.c:736: warning: implicit declaration of function 'kill'
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'pex_unix_pipe':
../../binutils-2.23.1/libiberty/pex-unix.c:754: warning: implicit declaration of function 'pipe'
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'pex_unix_fdopenw':
../../binutils-2.23.1/libiberty/pex-unix.c:770: error: 'F_SETFD' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c:770: error: 'FD_CLOEXEC' undeclared (first use in this function)
../../binutils-2.23.1/libiberty/pex-unix.c: In function 'pex_unix_cleanup':
../../binutils-2.23.1/libiberty/pex-unix.c:781: warning: identifier 'this' conflicts with C++ keyword
../../binutils-2.23.1/libiberty/pex-unix.c:784: warning: identifier 'this' conflicts with C++ keyword
../../binutils-2.23.1/libiberty/pex-unix.c:785: warning: identifier 'this' conflicts with C++ keyword
../../binutils-2.23.1/libiberty/pex-unix.c:786: warning: identifier 'this' conflicts with C++ keyword
Makefile:900: recipe for target `pex-unix.o' failed
make[2]: *** [pex-unix.o] Error 1
make[2]: Leaving directory `/cygdrive/c/dev/C++/MOSS/0.1/buildtools-master/build/binutils-obj/libiberty'
Makefile:7766: recipe for target `all-libiberty' failed
make[1]: *** [all-libiberty] Error 2
make[1]: Leaving directory `/cygdrive/c/dev/C++/MOSS/0.1/buildtools-master/build/binutils-obj'
Makefile:841: recipe for target `all' failed
make: *** [all] Error 2
Help? Thanks,