User:Sgielen/Patches

From Clean
Revision as of 23:57, 27 October 2010 by Sgielen (talk | contribs) (Adding patch page on my own server to this wiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

These are some of my patches to Clean. They make it possible (or /more/ possible) to build Clean on a Mac. For more information, check the Clean Wiki page on building Clean on Mac.

These patches are released as close to public domain as possible; do whatever you want with them.

Warning: I am in the process of moving this page from my own webserver to this Wiki. Stuff won't work yet. :)

RuntimeSystem patch

Apply outside the bootstrap package (you should have a clean/src/RuntimeSystem dir). This patch will create a new Makefile.macosx based on Makefile.linux, and make some source changes.

Download patch (last updated September 6, 2010)

Technical details on this patch

This patch changes the assembly in istartup.s. The construct used for ASCII values,

mov $' ',%ebx is invalid as described here. Characters in assembly should have only one singlequote character, i.e. mov $' ,%ebx , however, as I think this is confusing, I replaced all characters with their ASCII numeric counterparts: mov $32,%ebx .

CodeGenerator patch

Apply outside the bootstrap package (you should have a clean/src/CodeGenerator dir). This patch will create a new Makefile.macosx_intel{,64} based on Makefile.linux, and will improve debugging output in many cases. It also corrects some string formatting security bugs, and fixes FTBFS in some platform situations.

Important: Build using the Makefile.macosx_intel64 makefile, otherwise you will have problems generating code later (see this section on the Clean wiki).

Download patch (last updated September 6, 2010)

Technical details on this patch

The string formatting security bugs should speak for themselves in this patch. The code contained, in some places,

printf(string) instead of printf("%s",string) . This makes injection of format placeholders in the given string possible - an easy way to crash the application would be to send a string containing a few "%s%s%s", for example. The debugging output changes will be helpful later, when debugging the final build of Clean. I had to debug fopen() a lot, because it later occured to me that fopen had been redefined to a version of fopen() which mangles the path to open - this was fine for old Macs, but on recent ones it breaks file opening transparently.

The patch also adds an implementation of PowerPC's 'cntlzw' operation (Count Leading Zero's in Word), in C. It will undoubtedly be slower than the CPU op, but hopefully this won't be noticeable in the end.

Stdenv inclusion in the main Makefile

For me, stdenv inclusion while building the elf linker was necessary to build.

Download patch (last updated September 6, 2010)

CLM makefiles and debugging improvements

This patch adds a new Mac makefile and improves some debugging messages.

Download patch (last updated September 6, 2010)