分享
 
 
 

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

王朝system·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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 -))

Testuser@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 / grant@borg.umn.edu

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有