Building GCC 1.27

ciponi1 pts0 comments

Krister Walfridsson’s old blog: Building GCC 1.27

Saturday, January 26, 2019

Building GCC 1.27

GCC 1.27 was released in 1988 and is the first version of GCC supporting the x86 CPU. I thought it would be fun to make it work on my desktop computer.

Mikhail Maltsev wrote a great blog post about this a while back "Building and using a 29-year-old compiler on a modern system". I used Mikhail’s work as a starting point, but I built on a 64-bit Ubuntu system so I needed to update paths and as/ld options for running on a 64-bit OS, and I had much bigger problems with the ancient GCC not understanding the system headers. I also enabled the DBX debug format instead of the UNIX/32V SDB format that GDB does not understand. But I did not need to make that big changes to Mikhail’s patch.

It is amazing how well things work – the modern assembler, linker, and debugger handles the code generated by GCC 1.27 without any problems. And command options such as -O, -E, -S, -c, -g, -W, -pedantic, and -fomit-frame-pointer does what you expect from using a modern GCC. All the options are documented in the manual page – you can format the text by passing the gcc.1 file to man as

man -l gcc.1

How to build GCC 1.27 on Ubuntu

I have built the compiler on 64-bit Ubuntu Desktop 16.04 as described below.

Prerequisites

GCC 1.27 is a 32-bit program, so we need to install 32-bit compiler and runtime support

sudo apt install gcc-multilib

Downloading and preparing the source code

Download the source code and the patch, and apply the patch as

wget https://gcc.gnu.org/pub/gcc/old-releases/gcc-1/gcc-1.27.tar.bz2<br>wget https://gist.github.com/kristerw/b854b6d285e678452a44a6bcbf7ef86f/raw/gcc-1.27.patch<br>tar xf gcc-1.27.tar.bz2<br>cd gcc-1.27<br>patch -p1

Configuring the source code

The compiler is configured by setting up symbolic links to the correct configuration files

ln -s config-i386v.h config.h<br>ln -s tm-i386v.h tm.h<br>ln -s i386.md md<br>ln -s output-i386.c aux-output.c

You may want to change where the compiler is installed by updating bindir and libdir in the Makefile. I set them to

bindir = /home/kristerw/compilers/gcc-1.27/bin<br>libdir = /home/kristerw/compilers/gcc-1.27/lib

Build and install

The compiler is built in two (or three) stages, We start by building it using the system compiler

make

We then build it again using the newly built compiler

make stage1<br>make CC=stage1/gcc CFLAGS="-O -Bstage1/ -Iinclude"

As a third, optional, step, we build it again using the second compiler and checks that the resulting binaries are identical with the second compiler (if not, then the compiler has miscompiled itself).

make stage2<br>make CC=stage2/gcc CFLAGS="-O -Bstage2/ -Iinclude"<br>diff cpp stage2/cpp<br>diff gcc stage2/gcc<br>diff cc1 stage2/cc1

We are now ready to install the compiler

make install

Posted by

Krister Walfridsson

at

Saturday, January 26, 2019

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Labels:<br>C,<br>GCC

1 comment:

Jason StevensMay 5, 2019 at 4:06 AM<br>I've been using gcc 1.27 to build doom of all thing. I had to use the ASM version for the fixed math, as there is no long long type.

Anyways, I've been wondering how hard it would be to convert gcc 1.27 to compile to 32bit instructions & registers in long mode for a "64 bit" version.. although it'd require thunking to interface with any libraries....<br>ReplyDelete<br>Replies<br>Reply

Add comment

Load more...

Note: Only a member of this blog may post a comment.

Newer Post

Older Post

Home

Subscribe to:<br>Post Comments (Atom)

About this blog

This is my old, archived blog. New posts are published at https://kristerw.github.io/

Blog Archive

2021

(1)

October

(1)

2020

(1)

February

(1)

2019

(2)

April

(1)

January

(1)

Building GCC 1.27

2018

(10)

December

(1)

October

(1)

August

(1)

July

(1)

June

(2)

April

(1)

March

(1)

February

(1)

January

(1)

2017

(24)

December

(1)

October

(1)

September

(3)

August

(5)

July

(4)

June

(2)

May

(3)

April

(1)

March

(2)

February

(1)

January

(1)

2016

(23)

December

(2)

November

(4)

October

(2)

September

(2)

August

(1)

July

(3)

June

(1)

May

(2)

April

(2)

March

(2)

February

(1)

January

(1)

2015

(17)

October

(1)

August

(2)

July

(1)

June

(2)

May

(4)

April

(3)

March

(3)

February

(1)

Labels

backend

C++

C64

Epiphany

GCC

LLVM

NetBSD

nvptx

RISC-V

SMT solver

SPIR-V

Turing-complete

undefined behavior

Valgrind

x86

Popular Posts

Why undefined behavior may call a never-called function

Useful GCC warning options not enabled by -Wall -Wextra

Code behaving differently in C90, C99, C11, C++98, and C++11

GCC code generation for C++ Weekly Ep 43 example

How undefined signed overflow enables optimizations in GCC

Writing a GCC back end

C pointers are not hardware pointers

The structure of a GCC back end

Building GCC 1.27

How LLVM optimizes power sums

compiler make building blog january using

Related Articles