Difference between revisions of "User:Sgielen/Patches"

From Clean
Jump to navigationJump to search
(Include way more information on newest runtimesystem patch)
(Update to Clean 2.3 version →‎Stdenv inclusion in the main Makefile)
 
(5 intermediate revisions by the same user not shown)
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.
  
MD5 sum: d0c7a14afcfc02566c81e027e1a0c329
+
MD5 sum: 2e857ebe4295b00d6d725fa99c4ac6a9
  
[http://files.dazjorz.com/clean/clean_mac_runtimesystem.patch Download patch] (last updated October 28, 2010, version 3)
+
[http://files.dazjorz.com/clean/clean_mac_runtimesystem.patch Download patch] (last updated December 28, 2010, version 4)
  
 
=== Technical details on this patch ===
 
=== Technical details on this patch ===
Line 47: Line 47:
 
== CodeGenerator patch ==
 
== 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.
+
Apply outside the bootstrap package (you should have a clean/src/CodeGenerator dir). This patch will create a new Makefile.macosx based on Makefile.linux, and will improve debugging output in many cases. It also corrects some string formatting security bugs, and fixes FTBFS for x86-64 on Macs.
  
Important: Build using the Makefile.macosx_intel64 makefile, otherwise you will have problems generating code later (see this section on the Clean wiki).
+
This patch needs to be cleaned up sometime soon, because it contains a lot of unneeded debugging and obsolete changes. Also, this patch corrects only some cases of the printf format bug - that should be split off into a separate patch that fixes the problem at least everywhere in these files.
  
Download patch (last updated September 6, 2010)
+
MD5 sum: d257e6736f67c811fa2459c69f176b27
 +
 
 +
[http://files.dazjorz.com/clean/clean_mac_codegenerator.patch Download patch] (last updated December 28, 2010, version 4)
  
 
=== Technical details on this patch ===
 
=== Technical details on this patch ===
 +
 +
AT&T assembly mode is no longer needed - now that the guide uses the latest incarnation of GNU `gas`, the generated Intel ASM is just fine.
  
 
The string formatting security bugs should speak for themselves in this patch. The code contained, in some places,
 
The string formatting security bugs should speak for themselves in this patch. The code contained, in some places,
 +
<pre>printf(string)</pre>
 +
instead of
 +
<pre>printf("%s",string)</pre>
 +
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.
  
printf(string)
+
The debugging output changes may be helpful later, when debugging the final build of Clean.
instead of
+
 
printf("%s",string)
+
== CLM makefiles and debugging improvements ==
. 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.
+
This patch adds a new Makefile.macosx for CLM, improves some debugging messages, and enables AT&T assembly in the code generator. Now that the guide is using GNU `gas`, I don't think AT&T ASM is needed anymore, Intel ASM will do better. This patch should be updated to reflect that. Other than that, the patch is clean.
  
== Stdenv inclusion in the main Makefile ==
+
MD5 sum: 6d6f1af88c8401c53e71a12ba53ea59f
  
For me, stdenv inclusion while building the elf linker was necessary to build.
+
[http://files.dazjorz.com/clean/clean_mac_clm.patch Download patch] (last updated December 28, 2010, version 3)
  
Download patch (last updated September 6, 2010)
+
== Stdenv inclusion in the main Makefile ==
  
== CLM makefiles and debugging improvements ==
+
For me, stdenv inclusion while building the elf linker was necessary to build. '''This patch is not used in the guide yet, but it probably will be useful in the future.'''
  
This patch adds a new Mac makefile and improves some debugging messages.
+
MD5 sum: 0adf558225538feeed2e5a20c6ada1c0
  
Download patch (last updated September 6, 2010)
+
[http://files.dazjorz.com/clean/clean_mac_stdenvinclusion.patch Download patch] (last updated December 28, 2010, version 2)

Latest revision as of 13:47, 28 December 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: 2e857ebe4295b00d6d725fa99c4ac6a9

Download patch (last updated December 28, 2010, version 4)

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 based on Makefile.linux, and will improve debugging output in many cases. It also corrects some string formatting security bugs, and fixes FTBFS for x86-64 on Macs.

This patch needs to be cleaned up sometime soon, because it contains a lot of unneeded debugging and obsolete changes. Also, this patch corrects only some cases of the printf format bug - that should be split off into a separate patch that fixes the problem at least everywhere in these files.

MD5 sum: d257e6736f67c811fa2459c69f176b27

Download patch (last updated December 28, 2010, version 4)

Technical details on this patch

AT&T assembly mode is no longer needed - now that the guide uses the latest incarnation of GNU `gas`, the generated Intel ASM is just fine.

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 may be helpful later, when debugging the final build of Clean.

CLM makefiles and debugging improvements

This patch adds a new Makefile.macosx for CLM, improves some debugging messages, and enables AT&T assembly in the code generator. Now that the guide is using GNU `gas`, I don't think AT&T ASM is needed anymore, Intel ASM will do better. This patch should be updated to reflect that. Other than that, the patch is clean.

MD5 sum: 6d6f1af88c8401c53e71a12ba53ea59f

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

Stdenv inclusion in the main Makefile

For me, stdenv inclusion while building the elf linker was necessary to build. This patch is not used in the guide yet, but it probably will be useful in the future.

MD5 sum: 0adf558225538feeed2e5a20c6ada1c0

Download patch (last updated December 28, 2010, version 2)