Difference between revisions of "User:Sgielen/Patches"

From Clean
Jump to navigationJump to search
(Adding patch page on my own server to this wiki)
 
(Include way more information on newest runtimesystem patch)
Line 1: Line 1:
 
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 on Mac OS X|Clean Wiki page on building Clean on Mac]].
 
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 on Mac OS X|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.
+
These patches are released as close to public domain as possible; do whatever you want with them. Because this Wiki does not allow uploading .patch files, they are placed on my own webserver; an MD5 sum is included on this page.
  
 
'''Warning''': I am in the process of moving this page from my own webserver to this Wiki. Stuff won't work yet. :)
 
'''Warning''': I am in the process of moving this page from my own webserver to this Wiki. Stuff won't work yet. :)
Line 9: Line 9:
 
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.
 
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)
+
MD5 sum: d0c7a14afcfc02566c81e027e1a0c329
 +
 
 +
[http://files.dazjorz.com/clean/clean_mac_runtimesystem.patch Download patch] (last updated October 28, 2010, version 3)
  
 
=== Technical details on this patch ===
 
=== Technical details on this patch ===
  
This patch changes the assembly in istartup.s. The construct used for ASCII values,
+
This patch makes a few changes to assembly and C code. It makes sure that the assembly code is assemble-able and the C code compilable. I should check this patch through once more, because it might contain some changes that aren't needed anymore now that the [[Clean on Mac OS X]] page uses newest `gas`.
 +
 
 +
As for this hunk:
 +
 
 +
<pre>
 +
-  /* not portable to all compilers: */
 +
-#ifdef LINUX
 +
-/*
 +
-  if (file_p->_gptr < file_p->_egptr)
 +
-*/
 +
-  if (file_p->_IO_read_ptr < file_p->_IO_read_end)
 +
-#else
 +
-# ifdef OS2
 +
-  if (file_p->rcount>0)
 +
-# else
 +
-#  ifdef _WINDOWS_
 +
-  if (file_p->_r>0)
 +
-#  else
 +
-  if (file_p->_cnt>0)
 +
-#  endif
 +
-# endif
 +
-#endif
 +
-    return 0;
 +
+  file_p = f->file;
 +
+  if(feof(file_p))
 +
+    return -1;
 +
</pre>
  
mov $' ',%ebx
+
This was not portable at all. What I think the hunk does, is see if a read() call will block because there is no data available for reading. The function will return 0 if there is data available for reading, i.e. this method will "read ahead". However, this is an ugly hack, so I've simply removed it for a feof() function; I hope this will work and if it doesn't, I'll have to come up with another solution.
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 ==
 
== CodeGenerator patch ==

Revision as of 22:29, 28 October 2010

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. Because this Wiki does not allow uploading .patch files, they are placed on my own webserver; an MD5 sum is included on this page.

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.

MD5 sum: d0c7a14afcfc02566c81e027e1a0c329

Download patch (last updated October 28, 2010, version 3)

Technical details on this patch

This patch makes a few changes to assembly and C code. It makes sure that the assembly code is assemble-able and the C code compilable. I should check this patch through once more, because it might contain some changes that aren't needed anymore now that the Clean on Mac OS X page uses newest `gas`.

As for this hunk:

-   /* not portable to all compilers: */
-#ifdef LINUX
-/*
-   if (file_p->_gptr < file_p->_egptr)
-*/
-   if (file_p->_IO_read_ptr < file_p->_IO_read_end)
-#else
-# ifdef OS2
-   if (file_p->rcount>0)
-# else
-#  ifdef _WINDOWS_
-   if (file_p->_r>0)
-#  else
-   if (file_p->_cnt>0)
-#  endif
-# endif
-#endif
-     return 0;
+   file_p = f->file;
+   if(feof(file_p))
+     return -1;

This was not portable at all. What I think the hunk does, is see if a read() call will block because there is no data available for reading. The function will return 0 if there is data available for reading, i.e. this method will "read ahead". However, this is an ugly hack, so I've simply removed it for a feof() function; I hope this will work and if it doesn't, I'll have to come up with another solution.

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)