Building GCC as a Cross-compiler for Simplescalar/Alpha

转载 2012年03月21日 22:57:35

转自:http://hpc.serc.iisc.ernet.in/~sree/resources/building-cross-gcc-for-simplescalar.html 原链接已经失效


Building GCC as a Cross-compiler for Simplescalar/Alpha

NOTE: The instructions on this page are out of date (over three years old!) and unlikely to work on any modern GNU/Linux distribution. The page remains here for archival purposes only.

This page documents how I compiled GCC 3.4.6 and Binutils 2.17 that would output Alpha OSF/1 binaries on x86 systems. In particular, my aim was to get a modern compiler producing binaries that could be used as input to the Simplescalar/Alpha 3.0 suite.

The method presented here requires you to have access to Alpha Digital Unix OSF/1 system headers, libraries and binaries if you ever wish to repeat this procedure. Please check the Files section below for precompiled files that you may not get elsewhere.

I have only succeeded with the C and Fortran compilers, C++ support seems unlikely, given that libstdc++-v3 doesn't seem to support this target.

GCC 3.4.6 was used, since GCC 4.x seems to have problems with much source code. However, this method should work with GCC 4.x too.

ANSI C code should compile fine, Alpha-system-specific code could be problematic.

Systems used

  • Debian Etch 4.0 (x86_64 and i386)
  • Digital Unix OSF/1 4.0F (1229)

Why alpha-linux-gnu won't work

The compiler toolchain supports the alpha-linux-gnu target, which produces Alpha binaries for Linux systems. Unfortunately, Simplescalar has the following problems with this target:

  • alpha-linux-gnu produces ELF binaries, while Simplescalar requires COFF. However, this is not a big problem, since you can use objcopy to translate between the formats.
  • alpha-linux-gnu uses the GNU C Library, which in turn uses Linux system calls (not surprising for an alpha-linux-gnu system). Simplescalar only understands Ultrix system calls.

The target that must be used is alpha-dec-osf, which produces COFF binaries and with the native Alpha libraries, Ultrix system calls. Since that is the least GCC 3.x will support is alpha-dec-osf4, we will use this target.

Compiling Binutils

Binutils for the alpha-dec-osf4 target does not support GNU as and ld. We get around this by patching ld to "support" alpha-dec-osf4, and using the Alpha OSF/1 assembler under an Alpha emulator.

Patch binutils with this patch that enables GNU ld for alpha-dec-osf4, and also adds some missing symbol definitions (_DYNAMIC_LINK, _BASE_ADDRESS, _fpdata_size, _gpinfo) to its default Alpha linker script. This patching is sub-optimal, in that this does not cause GNU ld to behave like Alpha ld (esp. for exception handling). For most ANSI C programs, this should not be a problem -- your mileage with more Alpha-dependent code might vary.

Now compile binutils in the usual way, with target set to "alpha-dec-osf4" (and prefix to /usr).

On a Debian system (tested on Etch/4.0):

apt-get source binutils

cd binutils-2.17

patch -p1 < /path/to/patch-ld-syms-and-enable

TARGET="alpha-dec-osf4" fakeroot debian/rules binary-cross

sudo dpkg -i ../binutils-alpha-dec-osf4_2.17-*.deb

will compile and install Binutils for you. Make sure you have all the dependencies (build-essential, etc.)

Note that the above procedure installs the binutils in /usr/alpha-dec-osf4/, adjust commands below as necessary, especially if you compile from binutils sources (which would install to /usr/local).

Installing the Alpha assembler

  1. Copy the files as0 and as1 from Alpha OSF/1 to /usr/alpha-dec-osf4/bin.
  2. Copy sim-fast from your Simplescalar installation to /usr/alpha-dec-osf4/bin/alpha-emul. You might want to use this patch to make it quieter.
  3. Download this driver file and copy it to /usr/alpha-dec-osf4/bin
  4. Create a hard link:
    ln /usr/alpha-dec-osf4/bin/as /usr/bin/alpha-dec-osf4-as
    

Note: The driver as is very simple, and largely works. Improvements to make it more robust are welcome.

Alpha ld can't be used under Simplescalar

In case you were wondering why the Alpha ld couldn't be deployed using the same trick as Alpha as: the Alpha ld uses Mach microkernel system calls--Simplescalar complains about unimplemented negative numbered syscalls--which are perhaps too difficult to emulate. These NetBSD/Alpha docs have more info:

Compiling GCC 3.4.6

We compile GCC 3.4.6 from GNU sources, since the Debian package only supports a linux-gnu environment cross compile (see README.cross in the Debian sources) which means we wouldn't be able to use the native Alpha libc.

  1. Prepare a directory containing a portion of the Alpha sysroot, in particular, the following directories of an Alpha system:
    /usr/lib
    /usr/sys
    /usr/ccs
    /usr/includes
    
    Put these in, say, /tmp/alpha
  2. Copy the file /tmp/alpha/usr/ccs/lib/cmplrs/cc/crt0.o to /tmp/alpha/usr/lib. (TODO: Maybe specify this as --with-libs?)
  3. Make the directory /usr/alpha-dec-osf4 writable to the user who will compile GCC, so that the headers can be copied by gcc during configuration time.
    chown myuser.mygroup /usr/alpha-dec-osf4
    
  4. Copy /tmp/alpha/usr/{sys,ccs} to /usr/alpha-dec-osf4. The other directories will be copied by GCC's configure script.
  5. Download and uncompress GCC 3.4.6.
  6. Patch it with this patch, which replaces mips-tfile.c and mips-tdump.c with stubs. These files are officially known not to cross-compile. AFAICT, they add stabs debugging info, which is non-critical, IMO.
  7. Make a build directory outside the source tree, say /tmp/gb.
  8. Configure GCC in the build directory
    cd /tmp/gb 
    
    /path/to/gcc-3.4.6/configure --prefix=/usr \
    --program-prefix=alpha-dec-osf4- --disable-shared --disable-threads \
    --enable-languages=c,f77 --with-gnu-ld \
    --with-headers=/tmp/alpha/usr/include/ \
    --with-libs=/tmp/alpha/usr/lib/ --target=alpha-dec-osf4
    
    
    Note that --with-sysroot didn't work for me. The italic parts point out things you may have to change for your local site.
  9. Build GCC:
    make
  10. Install GCC:
    sudo make install

    Note: On a x86_64 system, the generated makefile might give sed errors during make install, just change:

    t='$(program_transform_name)'; echo ar | sed $$t
    
    to
    echo ar | sed '$(program_transform_name)'
    
    Repeat for all such instances (ranlib, etc.).

Validation

I've used the cross compiler generated to successfully compile and run:

  1. "Hello world" programs in Fortran and C.
  2. Simplescalar for Alpha, cross-compiled, and run with the native Simplescalar with itself as input (warped, but fun!):
    x86-linux-sim-fast alpha-sim-fast alpha-sim-fast
    
  3. The MediaBench suite, however ghostscript wouldn't compile due to linker errors

More as I test and validate this suite of compilers ...

Caveats

  • -ffast-math doesn't work, since some of the symbols required live in shared libraries, which GNU ld for the alpha doesn't support.

Files

Patches for GNU binutils+ldGCCsimplescalar.

Substitute for GNU as, containing alpha-emul (64-bit), as, as0 and as1.

Alpha OSF/1 partial sysroot containing headers and libraries.

Changelog

  • Nov 2010: Added obsolescence notice.
  • Jul 2008: Fix problems in Binutils compilation steps.
  • Mar 2008: Fixed typo in step 4 of "Compiling GCC", thank Keshavan!
  • Dec 2007: Original version

gcc源代码分析,genemit由i386.md文件生成insn-emit.c文件

第一部分输入的: ;; Call subroutine returning no value. (define_insn "call"   [(call (match_operand:QI 0 ...
  • sitelist
  • sitelist
  • 2014年01月11日 19:17
  • 1839

SimpleScalar 模拟器介绍

SimpleScalar 模拟器是一个超标量、5级流水的RISC体系结构模拟器,提供了从最简单到超标量乱序发射的不同的模拟程序。SimpleScalar工具集起源于80年代中后期由Manoj Fran...
  • dahogn
  • dahogn
  • 2015年04月21日 10:36
  • 1558

SimpleScalar的安装与配置

1. SimpleScalar的安装以Ubuntu 9.04系统下为例:(1)首先准备需要的安装文件,如果没有可到以下地址下载:simpletools-2v0.tgz: http://www.simp...
  • dahogn
  • dahogn
  • 2015年04月21日 21:21
  • 2152

升级gcc,glibc库途中遇到的各种问题

在互联网的世界中,总是会让人
  • u011037149
  • u011037149
  • 2014年08月04日 18:47
  • 6406

安装wxWidgets遭遇的两大关卡

早就想体验wxWidgets。这学期的C++课,课时还算充裕,关键是弟子们的实践能跟得上,我希望能让他们也浅尝一把GUI开发。MFC可以选,但既然IDE都用CodeBlocks了,还是选wxWidge...
  • sxhelijian
  • sxhelijian
  • 2014年05月13日 23:54
  • 14420

Simplescalar安装流程

竟然花了那么长时间来装一个破软件,感觉我要不把这些个步骤写下来,都没法向自己交代。。。 幸亏之前蛋疼地装了个Ubuntu玩,不然还得从操作系统搞起来,就更烦了。。。 先看安装包内的说明文档,发现这写的...
  • ldld1717
  • ldld1717
  • 2015年12月10日 09:07
  • 600

MyEclipse 优化配置以及Building Workspace时间太长的问题解决

刚毕业入职,对Java的概念还不是很有把握。平时在学校学习也都是一些小的项目,复杂度也不高,配置什么的也比较简单。但进入公司工作后,感觉写代码还是好说,但是每当一个工程从SVN检出后,总需要花一天半天...
  • qq_26651077
  • qq_26651077
  • 2017年08月01日 20:01
  • 647

gcc/g++命令参数中文帮助手册

引自: http://www.cnblogs.com/liangxiaxu/articles/2617367.htmlGCC 1Section: GNU Tools (1) Updated: 20...
  • zc02051126
  • zc02051126
  • 2015年09月23日 13:23
  • 3474

eclipse building workspace太慢或者 js出错问题解决

1.js文件错误解决办法   右键项目->properties->Builders(注:JavaScript Validator也会引起 build workspace太慢)   ...
  • crazzy0727
  • crazzy0727
  • 2016年11月03日 14:42
  • 3611

解决PKIX path building failed的问题-验证可以解决问题

在一次调试中,出现了这个错误:  Java代码   [ERROR] http-8080-Processor25 2010-01-20 15:29:28,640 org.ja...
  • ywb201314
  • ywb201314
  • 2017年06月01日 14:07
  • 619
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Building GCC as a Cross-compiler for Simplescalar/Alpha
举报原因:
原因补充:

(最多只允许输入30个字)