Plan 9 and Inferno at the Google Summer of Code

KenCC - Port of the Plan 9 compilers to *nix systems

The KenCC port is very usable at the moment. It can be found at http://gsoc.cat-v.org/hg/kenc and it comes in 6 parts:

8a      The Plan 9 386 assembler.
8c      The Plan 9 386 C compiler.
cc      The portable portions of the C compiler.
8l      The Plan 9 386 linker.
pcc     A wrapper around the compilers and linkers with a more
        POSIXy interface.
libcsu  The C startup linkage, namely _main() and operations on
        long long types not provided by the compiler.

The details: The linker will link Plan 9 .8 objects (binary 386 assembly language, as produced by the compiler and assembler), as well as ELF objects, along with their debugging information. It will also link agains ELF shared objects, though it can’t yet create them (and it doesn’t walk the dependency tree). It also generates basic debugging information (as much as the compilers provide) for .8 objects. It provides line number, stack frame/unwind, and param/auto variable location information (ELF objects come with whatever debugging info their compiler generated). There is currently no type information (all variables are represented as longs, unless cast otherwise), unless you use acid, for which the compiler can generate native debugging info. I intend on fixing this in the future.

I’d forgotten to upload the preprocessor, which only has one change, the -P flag, which is used to preinclude the pcc.h file, which provides varargck info for the POSIX formatted IO functions, and some defines to get around some GCC specific gunk (incorrectly) in BSD header files.

In the future, I’d like to support type information in debugging, PIC/SO generation, constructors/destructors (which seem totally inane to me; only for the linker), variable length auth arrays (for Plan 9 too, for the sake of porting code), more object types (I’ve tried to segregate the ELF related code; the BSDs still try to support COFF), and some other bits I’m forgetting.

On supporting other object types, 8l used to do it. At first, I tried to change as little as possible, but the code quickly became unwieldy, so I restructured the linker to work on sections, all the way down the line. The section related code should probably be made mostly ELF independant so (say) COFF and Plan 9 objects can be generated with little extra code (as it was before).

It would also be nice to port other archs. The ELF input/output code is not intwined with other archs, but it’s 32bit LEB specific. It would be nice, I think, to structure the linker code like the compiler code, in platform dependent and independent sections, since most of code relating to object format is totally platform independent. The compilers only required trivial changes (the register saving code was done in the linker; the calling convention changes were not extensive, and should be straightforward in the other compilers now that I’ve done it once), so porting them should be simple and forthcoming. I’d like very much for an AMD64 port, since it’s becoming so prevalent. It shouldn’t be too difficult.

Note: for building kenc you will need Inferno’s ar (iar), it can be found in inferno-os/utils/iar/ at the inferno-os repo.