Building GCC as a Cross-compiler for Simplescalar/Alpha

转自: 原链接已经失效

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:
    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:
  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
    echo ar | sed '$(program_transform_name)'
    Repeat for all such instances (ranlib, etc.).


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


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


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.


  • 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
个人分类: tools
想对作者说点什么? 我来说一句



Building GCC as a Cross-compiler for Simplescalar/Alpha