Difference between revisions of "User:Sgielen/Patches"

From Clean
Jump to navigationJump to search
(Include way more information on newest runtimesystem patch)
(Update text, add link →‎CodeGenerator 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: 4bc56357ef14e1016a2955a987535350
 +
 
 +
[http://files.dazjorz.com/clean/clean_mac_codegenerator.patch Download patch] (last updated October 28, 2010, version 3)
  
 
=== 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>
printf(string)
 
 
instead of
 
instead of
printf("%s",string)
+
<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.
+
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.
+
The debugging output changes may be helpful later, when debugging the final build of Clean.
  
 
== Stdenv inclusion in the main Makefile ==
 
== Stdenv inclusion in the main Makefile ==

Revision as of 23:49, 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 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: 4bc56357ef14e1016a2955a987535350

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

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.

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)