构建 GCC 1.27 (2019)
Building GCC 1.27 (2019)

原始链接: http://kristerw.blogspot.com/2019/01/building-gcc-127.html

本文详细介绍了在现代 64 位 Ubuntu 系统上成功构建并运行 GCC 1.27 的过程。GCC 1.27 发布于 1988 年,是首个支持 x86 CPU 的版本。 在 Mikhail Maltsev 先前工作的基础上,作者更新了路径以及汇编器/链接器选项,以确保其与 64 位架构的兼容性。主要的修改包括调整编译器以处理现代系统头文件,并启用 DBX 调试格式,从而确保与当代调试器的兼容。 值得注意的是,构建完成后的编译器功能依然完备,支持 `-O`、`-S` 和 `-g` 等标准命令行选项,并能与现代汇编器和链接器无缝集成。构建该项目需要安装 32 位库支持(`gcc-multilib`)、应用特定补丁、通过符号链接配置源码,并执行多阶段构建流程。该项目证明了 GCC 设计的持久生命力,也证实了由近 40 年前的编译器生成的代码,依然能被现代开发工具所解读。

Hacker News 新闻 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 构建 GCC 1.27 (2019) (kristerw.blogspot.com) 11 点,由 ciponi 发布于 4 小时前 | 隐藏 | 过往 | 收藏 | 1 条评论 帮助 leecommamichael 2 小时前 [–] 我想知道与现代工具相比,它的构建需要多久,以及生成可执行文件的速度有多快。 回复 考虑申请 YC 2026 年秋季批次!申请截止日期为 7 月 27 日。 准则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

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
wget https://gist.github.com/kristerw/b854b6d285e678452a44a6bcbf7ef86f/raw/gcc-1.27.patch
tar xf gcc-1.27.tar.bz2 
cd gcc-1.27
patch -p1 < ../gcc-1.27.patch

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
ln -s tm-i386v.h tm.h
ln -s i386.md md
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
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
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
make CC=stage2/gcc CFLAGS="-O -Bstage2/ -Iinclude"
diff cpp stage2/cpp
diff gcc stage2/gcc
diff cc1 stage2/cc1
We are now ready to install the compiler
make install
联系我们 contact @ memedata.com