← Thu, Sep 24 digest

Making portable my unportable transputer C compiler

read article ↗ hn thread ↗

Oscar Toledo G. ports his 1998 C compiler for the Transputer to 64-bit systems by replacing legacy byte-pool structures with proper ANSI C structs.

read it A delightful dive into retro-compilers, legacy code modernization, and low-level debugging across architectures.

summary

Oscar Toledo G. retrieved a 1998 C compiler for the Transputer architecture and attempted to build it on a modern 64-bit Mac. He encountered major portability hurdles caused by legacy Small-C patterns, such as mixing pointers with 32-bit integers, lacking function prototypes, and storing custom structures in raw byte pools. By backporting struct definitions from a later project and cleaning up the codebase, he achieved successful compilation. Testing it in a Transputer emulator ultimately uncovered an unrelated out-of-memory bug where malloc failed to return NULL.

key points

  1. Legacy Small-C code heavily interchanged 32-bit integers and pointers, breaking compilation on modern 64-bit systems.
  2. Clean struct definitions from a later compiler project replaced hardcoded byte-pool offsets.
  3. A persistent compiler crash during self-hosting was ultimately traced to an OS bug where malloc failed to return NULL upon exhaustion.

who should read it

Retrocomputing enthusiasts, compiler engineers, and low-level systems programmers.

discussion warm

consensus

Commenters express delight at the retrocomputing project and relate to finding unexpected bugs in unrelated system components like malloc.

best comment by nanochess ↗

It is a simple debugger log in the transputer emulator (enabled by compilation option) which outputs each instruction executed so far, around 70 bytes per line displaying the 3 registers, the stack pointer, the instruction pointer, and the disassembled instruction.

The emulated C compiler processed a whole file ccvars.c before getting stuck in ccinter.c (this is the 5gb mark, approximately 78 millions of instructions executed). I stopped the process as soon as I saw it was stuck, but the emulator is fast, and I got extra 3 gb in the log. All this happened in less than two minutes.

The author explains how an 8GB debug log was generated in under two minutes by dumping instruction traces from the transputer emulator.

Generated by an LLM from the article and thread. Check the sources before relying on it.