Binutils 2.15 for BeOS patches

Marcin Konicki ahwayakchih@neoni.net
Tue Dec 7 08:22:00 GMT 2004


Hi,

I've build and used binutils 2.15 for some time now. There are only few 
changes needed to make it work on BeOS.
There was a problem with combined relocations, and i used workaround for 
that (BIG THX to Nick Clifton who helped me A LOT finding out what's wrong 
:), but Oliver Tappe had found better solution for that, so no point to 
use the one i used.
So i'm sending only bfdio patch which fixes problem with BeOS not writing 
zeros to file between last written data and fseek after that.
I used solution descriped in posts 
http://sources.redhat.com/ml/binutils/2002-09/msg00356.html and
http://sources.redhat.com/ml/binutils/2002-09/msg00368.html , which should 
be better than the one Be used in their port of binutils 2.10 (IIRC). At 
least according to those posts :)

It probably won't be accepted but at least other people with similar 
problem may use it :)

THX
Regards
ahwayakchih
-------------- next part --------------
--- binutils-2.15/bfd/bfdio.c-	Thu Feb 12 00:23:20 2004
+++ binutils-2.15/bfd/bfdio.c	Mon Dec  6 12:57:31 2004
@@ -38,6 +38,13 @@
 #define S_IXOTH 0001    /* Execute by others.  */
 #endif
 
+#ifdef __BEOS__
+
+#include <kernel/image.h>
+int _bfdio_files[OPEN_MAX+1];
+
+#endif
+
 file_ptr
 real_ftell (FILE *file)
 {
@@ -53,6 +60,9 @@
 int
 real_fseek (FILE *file, file_ptr offset, int whence)
 {
+#ifdef __BEOS__
+  _bfdio_files[fileno(file)] = 1;
+#endif
 #if defined (HAVE_FSEEKO64)
   return fseeko64 (file, offset, whence);
 #elif defined (HAVE_FSEEKO)
@@ -174,8 +184,44 @@
       abfd->where += size;
       return size;
     }
+#if defined (__BEOS__)
+    {
+     FILE *f;
+     f = bfd_cache_lookup (abfd);
+     if (_bfdio_files[fileno(f)] == 1)
+       {
+         file_ptr eof;
+         file_ptr pos;
+          
+         pos = ftell (f);
+         fseek (f, 0L, SEEK_END);
+         eof = ftell(f);
+          
+         if (eof < pos)
+           {
+             file_ptr diff;
+             static char zeros[512];
+
+             diff = pos - eof;
+              
+             while (diff >= 512)
+               {
+                 fwrite(zeros, 512, 1, f);
+                 diff -= 512;
+               }
+             if (diff > 0)
+               fwrite(zeros, diff, 1, f);
+           }
+         fseek (f, pos, SEEK_SET);
+
+         _bfdio_files[fileno(f)] = 0;
+       }
 
+       nwrote = fwrite (ptr, 1, (size_t) size, f);
+      }
+#else
   nwrote = fwrite (ptr, 1, (size_t) size, bfd_cache_lookup (abfd));
+#endif
   if (nwrote != (size_t) -1)
     abfd->where += nwrote;
   if (nwrote != size)


More information about the Binutils mailing list