Building a GCC PowerPC/Linux Cross Compiler For SPARC/Solaris

类别:编程语言 点击:0 评论:0 推荐:
Building a GCC PowerPC/Linux Cross Compiler For SPARC/Solaris

There are a number of resources on the Internet serving as a guide for building a cross compiler. However, each addresses a particular version of the compiler as well as a particular host/target combination; which while generally useful as a base instruction set, doesn't cover the intricacies of performing the feat for a different version and host/target combination. This attempts to document the process of building a GCC 2.95.2 cross compiler for PowerPC/Linux 2.4.0 on SPARC/ Solaris 2.7 (aka Solaris 7, SunOS 5.7).

Conventions

In the instructions below, the following conventions are used:

<archive dir> Location in which you store your archive (i.e. *.tar.gz) files. <source dir> Location in which you unpack your archive files as various source directories. <object dir> Location in which you will build object files from the source dirctories located in <source dir>. This may be the same as <source dir>; however, that is not recommended. <tool dir> Location in which you will place all of the built cross-compiler tools and libraries. gmake GNU version of make gtar GNU version of tar Instructions

Most of the following steps should work fine with default system tools. However, the process for building tends to make a number of assumptions about running with a GNU tool set, in particular, a native GCC compiler. That said, it may be useful (I certainly found it to be) to have /usr/local/gnu/bin or an equivalent GNU tool set in your PATH before your normal system tools (/usr/bin, /usr/xpg4/bin, /usr/ucb, etc.). I used these tools.

It is also highly encouraged that all the below commands be run while using bash (preferrably) or ksh as your shell. You will likely even have better luck if you set the environment variable SHELL to bash or ksh. All the subsequent examples will assume that this is the case. Adjust accordingly if you are using csh, tcsh or some other shell.

Changing the optimization level of the compiler (e.g. -O3), either via CFLAGS or by another means, is not recommened. Doing so will likely result in either a failed build step in glibc or a broken cross-compilation environment.

Packages

The following packages are required for this endeavor:

Package Version Location binutils 2.10.1 Download gcc-core 2.95.2 Download gcc 2.95.2 Download glibc 2.1.3 Download glibc-crypt 2.1.3 Download glibc-linuxthreads 2.1.3 Download linux 2.4.0 Download

Binutils Extract cd <source dir> gtar zxvf <archive dir>/binutils-2.10.1.tar.gz

Build mkdir <tool dir>/host mkdir <tool dir>/host/sparc-sun-solaris mkdir <object dir>/binutils-2.10.1 cd <object dir>/binutils-2.10.1 <source dir>/binutils-2.10.1/configure --host=sparc-sun-solaris --target=powerpc-linux --prefix=<tool dir>/host/sparc-sun-solaris gmake

Install gmake install gmake install-info

Access

Subsequent build steps will need to use the tools created by this step. As such, the path to these tools will need to be added to your environment's PATH variable:

PATH=${PATH}":<tool dir>/host/sparc-sun-solaris/bin" export PATH

Gcc (Core) Extract cd <source dir> gtar zxvf <archive dir>/gcc-core-2.95.2.tar.gz

Build mkdir <object dir>/gcc-2.95.2 cd <object dir>/gcc-2.95.2 <source dir>/gcc-2.95.2/configure --host=sparc-sun-solaris --target=powerpc-linux --prefix=<tool dir>/host/sparc-sun-solaris --with-newlib gmake

Install gmake install

Linux Headers

The 2.4.0 kernel contains PowerPC support; however, it may not contain the absolute latest bleeding-edge changes to accomodate various PowerPC architectures. Such changes are maintained elsewhere.

Extract cd <source dir> gtar zxvf <archive dir>/linux-2.4.0.tar.gz

Build cd <source dir>/linux Edit the Makefile Comment out the existing "ARCH :=" line and add a new line with "ARCH := ppc". line. Find the "CROSS_COMPILE =" line and append 'powerpc-linux-' so that it reads "CROSS_COMPILE = powerpc-linux-"

If you have Tcl/Tk installed, then "gmake xconfig", or if you have the GNU ncurses library installed, then "gmake menuconfig", otherwise "gmake config" . gmake dep gmake clean gmake zImage

The zImage build process does not have to complete successfully; only the headers are required.

Verify

Verify that the headers were created.

find ./include/. -name "version.h"

You should see output similar to: "./include/./linux/version.h".

If you do not have the appropriate headers, use the "gmake distclean" command and repeat the steps for this section again.

Glibc Link ln -sf <linux source dir>/include/asm <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/asm ln -sf <linux source dir>/include/linux <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/linux ls -la <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/asm/* ls -la <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/linux/*

Extract cd <source dir> gtar zxvf <archive dir>/glibc-2.1.3.tar.gz cd <source dir>/glibc-2.1.3 gtar zxvf <archive dir>/glibc-crypt-2.1.3.tar.gz gtar zxvf <archive dir>/glibc-linuxthreads-2.1.3.tar.gz

Build

First, Create a separate subdirectory, such as <tool dir> /target/powerpc-linux-gnu in which to install the glibc libraries. This will be the target of the --prefix configure switch.

The configure script is quite specific about what versions (and flavors) of various build tools it requires. If it doesn't find what it's looking for, chance are that things won't build. Try to appease it.

mkdir <tool dir>target mkdir <tool dir>target/powerpc-linux-gnu mkdir <object dir>/glibc-2.1.3 cd <object dir>/glibc-2.1.3 CC=powerpc-linux-gcc AR=powerpc-linux-ar RANLIB=powerpc-linux-ranlib <source dir>/glibc-2.1.3/configure --host=powerpc-linux --with-headers=<linux source dir>/include --enable-add-ons=crypt,linuxthreads --enable-shared --prefix=<tool dir>/target/powerpc-linux-gnu gmake

There are a few likely pitfalls here. First, depending on which echo the make process finds (SVR4, BSD, GNU, shell built-in, etc.) there will be an error in csu/version-info.h if it picks the wrong one. Picking the wrong one results in '-n Version...' rather than the intended 'Version...' in csu/version-info.h.

You will also probably notice in the csu/version-info.h file that it reports that it was compiled "on a Linux 5.7 system". This should report "on a Linux 2.4.0 system". This due to more echo problems. The actual content doesn't really matter, it just affects what it output when /usr/lib/libc.so is executed.

Edit and fix the csu/version-info.h file as necessary. gmake

The second pitfall when building on a stock Solaris 2.7 machine, is that there is a limit of 64 open file descriptors. This will result in an error building in the iconvdata/ subdirectory. This can be remedied by ratcheting up the limit to 1024:

/usr/bin/ulimit -n 1024 gmake

The overall build process should take several hours to complete, even on the brawniest of hardware.

Install gmake install

If your build process has completed successfully, the install process should go fairly smoothly. One tangle may occur when the install process attempts to run in the locale/ directory. There are either missing rules for, or the rules don't work quite correctly for, the i18n/locales/ and i18n/repertoiremaps/ targets.

If you encounter this problem, to work around it, simply create the following directories yourself:

cd <tool dir>/target/powerpc-linux-gnu/share/ mkdir i18n cd i18n mkdir locales mkdir repertoiremaps cd <object dir>/glibc-2.1.3 gmake install

The install process should take about 15 or so minutes, assuming that no errors are encountered.

GCC

Provided that glibc compiled successfully, you are ready to go back and rebuild the C compiler and, if you wish, build the Objective C, C++ and F77 compilers.

Extract cd <source dir> mv gcc-2.95.2 gcc-core-2.95.2 gtar zxvf <archive dir>/gcc-2.95.2.tar.gz

Build cd <object dir> mv gcc-2.95.2 gcc-core-2.95.2 mkdir gcc-2.95.2 cd gcc-2.95.2 <source dir>/gcc-2.95.2/configure --host=sparc-sun-solaris --target=powerpc-linux --prefix=<tool dir>/host/sparc-sun-solaris --with-headers=<tool dir>/target/powerpc-linux-gnu/include --with-libs=<tool dir>/target/powerpc-linux-gnu/lib --enable-shared --enable-languages="c,c++,f77" gmake

Install gmake install

Fix Up

Once you have successfully built and installed everything, there are a few minor fix ups that need to be done to complete the installation. The primary outcome of the following steps is to remove the duplicate copies of the target headers and libraries and to permanent copy in the Linux headers. If you do not want to do this, you can safely skip this step.

cd <tool dir>/host/sparc-sun-solaris/powerpc-linux/ rm -f include/asm rm -f include/linux rm -rf include/ mv lib/ldscripts lib/nof lib/libstdc++-* <tool dir>/target/powerpc-linux-gnu/lib rm -f lib/ sys-include/ ln -si <tool dir>/target/powerpc-linux-gnu/include include ln -si <tool dir>/target/powerpc-linux-gnu/lib lib ln -si include sys-include mkdir <tool dir>/target/powerpc-linux-gnu/include/asm mkdir <tool dir>/target/powerpc-linux-gnu/include/linux (cd <source dir>/linux/include/asm; tar cf - . | (cd <tool dir>/target/powerpc-linux-gnu/include/asm; tar xfBp -)) (cd <source dir>/linux/include/linux; tar cf - . | (cd <tool dir>/target/powerpc-linux-gnu/include/linux; tar xfBp -))

Test

user@ultraSPARC% pwd /home/user user@ultraSPARC% uname -a SunOS ultraSPARC 5.7 Generic sun4u sparc user@ultraSPARC% cat > hello.c #include <stdio.h> int main (int argc, char *argv[]) { printf("Hello, %s!\n", argc >= 2 ? argv[1] : "world"); return (0); } user@ultraSPARC% cat > hello.C #include <iostream.h> int main (int argc, char *argv[]) { cout << "Hello, " << ((argc >= 2) ? argv[1] : "world") << "!" << endl; return (0); } user@ultraSPARC% cat > hello.f program hello print*,'Hello, world!' end user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-gcc -dumpmachine powerpc-linux user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-gcc -o helloc -s hello.c user@ultraSPARC% file helloc hello-c: ELF 32-bit MSB executable PowerPC Version 1, dynamically linked, stripped user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g++ -dumpmachine powerpc-linux user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g++ -o helloC -s hello.C user@ultraSPARC% file helloC hello-c: ELF 32-bit MSB executable PowerPC Version 1, dynamically linked, stripped user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g77 -dumpmachine powerpc-linux user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g77 -o hellof -s hello.f user@ultraSPARC% file hellof hello-c: ELF 32-bit MSB executable PowerPC Version 1, dynamically linked, stripped user@ultraSPARC% rsh PowerMac user@PowerMac% pwd /home/user user@PowerMac% uname -a Linux PowerMac 2.4.0-test12 #1 Mon Jan 8 12:34:22 CST 2001 ppc unknown user@PowerMac% file helloc hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked, stripped user@PowerMac% file helloC hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked, stripped user@PowerMac% file hellof hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked, stripped user@PowerMac% ldd ./helloc libc.so.6 => /lib/libc.so.6 (0x016be000) /lib/ld.so.1 => /lib/ld.so.1 (0x30000000) user@PowerMac% ldd ./helloC libstdc++.so.2.9 => /usr/lib/libstdc++.so.2.9 (0x0175b000) libm.so.6 => /lib/libm.so.6 (0x01783000) libc.so.6 => /lib/libc.so.6 (0x01641000) /lib/ld.so.1 => /lib/ld.so.1 (0x30000000) user@PowerMac% ldd ./hellof libm.so.6 => /lib/libm.so.6 (0x01783000) libc.so.6 => /lib/libc.so.6 (0x01641000) /lib/ld.so.1 => /lib/ld.so.1 (0x30000000) user@PowerMac% ./helloc Hello, world! user@PowerMac% ./helloC Hello, world! user@PowerMac% ./hellof Hello, world! Adding On

With a complete cross-development environment now in place, you are now ready to build and install other headers and libraries, such as termcap or readline, into the <tool dir>/target/powerpc-linux-gnu subdirectory.

Parting Notes

Building all of the above requires a significant amount of space, on the order of 150 MB for the powerpc-linux cross-development system hosted on Sun Solaris 2.7. None of the above tools are stripped by default, so doing so after installation will save an appreciable amount of space.

Useful Resources http://gcc.cygnus.com/install/index.html http://penguinppc.org/embedded/cross-compiling/ http://developer.intel.com/design/strong/applnots/sa1100lx/sa1100lx.htm http://www.objsw.com/CrossGCC/ Last modified: Thu May 10 10:42:23 CDT 2001
Grant Erickson / [email protected]

本文地址:http://com.8s8s.com/it/it23698.htm