public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [rfa] Add bfd-in-memory io vector
@ 2004-04-30 22:03 Andrew Cagney
  2004-04-30 22:12 ` DJ Delorie
  2004-05-01 18:10 ` Andrew Cagney
  0 siblings, 2 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-04-30 22:03 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 498 bytes --]

Hello,

This adds a bfd-in-memory IO vector to BFD.  Note that it doesn't 
completly consolidate code using "struct bfd_in_memory" as some of it is 
pretty evil (grep for remaining references to BFD_IN_MEMORY).  I'll do 
another pass at eliminating more of the BFD_IN_MEMORY references in a 
follow-up patch.

I've tested this on i386 GNU/Linux with no regressions.  However, given 
my experience with the previous IOVEC change, I'm not sure how 
significant that result is :-/

Anyway, Ok?
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 14023 bytes --]

2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* libbfd-in.h (_bfd_in_memory): Declare.
	* libbfd.h: Re-generate.
	* opncls.c (bim_bread, bim_bwrite, bim_btell, bim_bflush, bim_bstat) 
	(bim_bseek, bim_bclose, bim_iovec, _bfd_in_memory): Implement BFD
	in memory.
	(bfd_close): Delete bfd-in-memory code.
	(bfd_make_writable): Use _bfd_in_memory.
	* bfdio.c (bfd_bread, bfd_bwrite, bfd_tell, bfd_flush, bfd_stat) 
	(bfd_seek, bfd_get_size): Delete bfd-in-memory code.
	* elfcode.h (bfd_from_remote_memory): Use _bfd_in_memory.
	* xcofflink.c (bfd_xcoff_link_generate_rtinit): Ditto.
	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Ditto.

Index: bfdio.c
===================================================================
RCS file: /cvs/src/src/bfd/bfdio.c,v
retrieving revision 1.6
diff -p -u -r1.6 bfdio.c
--- bfdio.c	21 Apr 2004 17:05:11 -0000	1.6
+++ bfdio.c	30 Apr 2004 21:38:39 -0000
@@ -97,7 +97,6 @@ DESCRIPTION
 
 */
 
-
 /* Return value is amount read.  */
 
 bfd_size_type
@@ -105,26 +104,6 @@ bfd_bread (void *ptr, bfd_size_type size
 {
   size_t nread;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    {
-      struct bfd_in_memory *bim;
-      bfd_size_type get;
-
-      bim = abfd->iostream;
-      get = size;
-      if (abfd->where + get > bim->size)
-	{
-	  if (bim->size < (bfd_size_type) abfd->where)
-	    get = 0;
-	  else
-	    get = bim->size - abfd->where;
-	  bfd_set_error (bfd_error_file_truncated);
-	}
-      memcpy (ptr, bim->buffer + abfd->where, (size_t) get);
-      abfd->where += get;
-      return get;
-    }
-
   nread = abfd->iovec->bread (abfd, ptr, size);
   if (nread != (size_t) -1)
     abfd->where += nread;
@@ -137,33 +116,6 @@ bfd_bwrite (const void *ptr, bfd_size_ty
 {
   size_t nwrote;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    {
-      struct bfd_in_memory *bim = abfd->iostream;
-      size = (size_t) size;
-      if (abfd->where + size > bim->size)
-	{
-	  bfd_size_type newsize, oldsize;
-
-	  oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	  bim->size = abfd->where + size;
-	  /* Round up to cut down on memory fragmentation */
-	  newsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	  if (newsize > oldsize)
-	    {
-	      bim->buffer = bfd_realloc (bim->buffer, newsize);
-	      if (bim->buffer == 0)
-		{
-		  bim->size = 0;
-		  return 0;
-		}
-	    }
-	}
-      memcpy (bim->buffer + abfd->where, ptr, (size_t) size);
-      abfd->where += size;
-      return size;
-    }
-
   nwrote = abfd->iovec->bwrite (abfd, ptr, size);
   if (nwrote != (size_t) -1)
     abfd->where += nwrote;
@@ -182,9 +134,6 @@ bfd_tell (bfd *abfd)
 {
   file_ptr ptr;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    return abfd->where;
-
   ptr = abfd->iovec->btell (abfd);
 
   if (abfd->my_archive)
@@ -196,8 +145,6 @@ bfd_tell (bfd *abfd)
 int
 bfd_flush (bfd *abfd)
 {
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    return 0;
   return abfd->iovec->bflush (abfd);
 }
 
@@ -208,9 +155,6 @@ bfd_stat (bfd *abfd, struct stat *statbu
 {
   int result;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    abort ();
-
   result = abfd->iovec->bstat (abfd, statbuf);
   if (result < 0)
     bfd_set_error (bfd_error_system_call);
@@ -234,47 +178,6 @@ bfd_seek (bfd *abfd, file_ptr position, 
   if (direction == SEEK_CUR && position == 0)
     return 0;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    {
-      struct bfd_in_memory *bim;
-
-      bim = abfd->iostream;
-
-      if (direction == SEEK_SET)
-	abfd->where = position;
-      else
-	abfd->where += position;
-
-      if (abfd->where > bim->size)
-	{
-	  if ((abfd->direction == write_direction) ||
-	      (abfd->direction == both_direction))
-	    {
-	      bfd_size_type newsize, oldsize;
-	      oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	      bim->size = abfd->where;
-	      /* Round up to cut down on memory fragmentation */
-	      newsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	      if (newsize > oldsize)
-	        {
-		  bim->buffer = bfd_realloc (bim->buffer, newsize);
-		  if (bim->buffer == 0)
-		    {
-		      bim->size = 0;
-		      return -1;
-		    }
-	        }
-	    }
-	  else
-	    {
-	      abfd->where = bim->size;
-	      bfd_set_error (bfd_error_file_truncated);
-	      return -1;
-	    }
-	}
-      return 0;
-    }
-
   if (abfd->format != bfd_archive && abfd->my_archive == 0)
     {
 #if 0
@@ -407,9 +310,6 @@ long
 bfd_get_size (bfd *abfd)
 {
   struct stat buf;
-
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    return ((struct bfd_in_memory *) abfd->iostream)->size;
 
   if (abfd->iovec->bstat (abfd, &buf) != 0)
     return 0;
Index: coff-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-alpha.c,v
retrieving revision 1.20
diff -p -u -r1.20 coff-alpha.c
--- coff-alpha.c	30 Apr 2004 14:23:39 -0000	1.20
+++ coff-alpha.c	30 Apr 2004 21:38:39 -0000
@@ -2086,7 +2086,6 @@ alpha_ecoff_get_elt_at_filepos (archive,
   bfd_byte ab[8];
   bfd_size_type size;
   bfd_byte *buf, *p;
-  struct bfd_in_memory *bim;
 
   nbfd = _bfd_get_elt_at_filepos (archive, filepos);
   if (nbfd == NULL)
@@ -2181,19 +2180,11 @@ alpha_ecoff_get_elt_at_filepos (archive,
     }
 
   /* Now the uncompressed file contents are in buf.  */
-  bim = ((struct bfd_in_memory *)
-	 bfd_alloc (nbfd, (bfd_size_type) sizeof (struct bfd_in_memory)));
-  if (bim == NULL)
+  if (!_bfd_in_memory (nbfd, nbfd->flags, buf, size))
     goto error_return;
-  bim->size = size;
-  bim->buffer = buf;
 
   nbfd->mtime_set = TRUE;
   nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10);
-
-  nbfd->flags |= BFD_IN_MEMORY;
-  nbfd->iostream = (PTR) bim;
-  BFD_ASSERT (! nbfd->cacheable);
 
   return nbfd;
 
Index: elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.55
diff -p -u -r1.55 elfcode.h
--- elfcode.h	22 Apr 2004 14:45:31 -0000	1.55
+++ elfcode.h	30 Apr 2004 21:38:40 -0000
@@ -1690,28 +1690,22 @@ NAME(_bfd_elf,bfd_from_remote_memory)
   memcpy (contents, &x_ehdr, sizeof x_ehdr);
 
   /* Now we have a memory image of the ELF file contents.  Make a BFD.  */
-  bim = bfd_malloc (sizeof (struct bfd_in_memory));
-  if (bim == NULL)
+  nbfd = _bfd_new_bfd ();
+  if (nbfd == NULL)
     {
       free (contents);
       bfd_set_error (bfd_error_no_memory);
       return NULL;
     }
-  nbfd = _bfd_new_bfd ();
-  if (nbfd == NULL)
+  if (!_bfd_in_memory (nbfd, 0, contents, contents_size))
     {
-      free (bim);
       free (contents);
+      bfd_close (nbfd);
       bfd_set_error (bfd_error_no_memory);
       return NULL;
     }
   nbfd->filename = "<in-memory>";
   nbfd->xvec = templ->xvec;
-  bim->size = contents_size;
-  bim->buffer = contents;
-  nbfd->iostream = bim;
-  nbfd->flags = BFD_IN_MEMORY;
-  nbfd->direction = read_direction;
   nbfd->mtime = time (NULL);
   nbfd->mtime_set = TRUE;
 
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.33
diff -p -u -r1.33 libbfd-in.h
--- libbfd-in.h	30 Apr 2004 14:23:39 -0000	1.33
+++ libbfd-in.h	30 Apr 2004 21:38:40 -0000
@@ -50,6 +50,9 @@ struct bfd_in_memory
   bfd_byte *buffer;
 };
 
+int _bfd_in_memory (struct bfd *abfd, flagword flags, void *buffer,
+		    bfd_size_type size);
+
 /* tdata for an archive.  For an input archive, cache
    needs to be free()'d.  For an output archive, symdefs do.  */
 
Index: opncls.c
===================================================================
RCS file: /cvs/src/src/bfd/opncls.c,v
retrieving revision 1.23
diff -p -u -r1.23 opncls.c
--- opncls.c	23 Apr 2004 00:22:57 -0000	1.23
+++ opncls.c	30 Apr 2004 21:38:40 -0000
@@ -1,7 +1,7 @@
 /* opncls.c -- open and close a BFD.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
-   2001, 2002, 2003
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Written by Cygnus Support.
 
@@ -501,6 +501,185 @@ bfd_openr_iovec (const char *filename, c
   return nbfd;
 }
 \f
+
+
+/* BFD in memory.  */
+
+static file_ptr
+bim_btell (struct bfd *abfd)
+{
+  return abfd->where;
+}
+
+static int
+bim_bseek (struct bfd *abfd, file_ptr offset, int whence)
+{
+  struct bfd_in_memory *bim;
+
+  bim = abfd->iostream;
+      
+  if (whence == SEEK_SET)
+    abfd->where = offset;
+  else
+    abfd->where += offset;
+  
+  if (abfd->where > bim->size)
+    {
+      if ((abfd->direction == write_direction) ||
+	  (abfd->direction == both_direction))
+	{
+	  bfd_size_type newsize, oldsize;
+	  oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
+	  bim->size = abfd->where;
+	  /* Round up to cut down on memory fragmentation */
+	  newsize = (bim->size + 127) & ~(bfd_size_type) 127;
+	  if (newsize > oldsize)
+	    {
+	      bim->buffer = bfd_realloc (bim->buffer, newsize);
+	      if (bim->buffer == 0)
+		{
+		  bim->size = 0;
+		  return -1;
+		}
+	    }
+	}
+      else
+	{
+	  abfd->where = bim->size;
+	  bfd_set_error (bfd_error_file_truncated);
+	  return -1;
+	}
+    }
+  return 0;
+}
+
+static file_ptr
+bim_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
+{
+  struct bfd_in_memory *bim;
+  bfd_size_type get;
+  
+  bim = abfd->iostream;
+  get = nbytes;
+  if (abfd->where + get > bim->size)
+    {
+      if (bim->size < (bfd_size_type) abfd->where)
+	get = 0;
+      else
+	get = bim->size - abfd->where;
+    }
+  memcpy (buf, bim->buffer + abfd->where, (size_t) get);
+  abfd->where += get;
+  return get;
+}
+
+static file_ptr
+bim_bwrite (struct bfd *abfd, const void *where, file_ptr nbytes)
+{
+  struct bfd_in_memory *bim = abfd->iostream;
+  size_t size;
+
+  size = (size_t) nbytes;
+  if (abfd->where + size > bim->size)
+    {
+      bfd_size_type newsize, oldsize;
+      
+      oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
+      bim->size = abfd->where + size;
+      /* Round up to cut down on memory fragmentation */
+      newsize = (bim->size + 127) & ~(bfd_size_type) 127;
+      if (newsize > oldsize)
+	{
+	  bim->buffer = bfd_realloc (bim->buffer, newsize);
+	  if (bim->buffer == 0)
+	    {
+	      bim->size = 0;
+	      return 0;
+	    }
+	}
+    }
+  memcpy (bim->buffer + abfd->where, where, size);
+  abfd->where += size;
+  return size;
+}
+
+static int
+bim_bclose (struct bfd *abfd ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+static int
+bim_bflush (struct bfd *abfd ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+static int
+bim_bstat (struct bfd *abfd, struct stat *sb)
+{
+  struct bfd_in_memory *bim = abfd->iostream;
+
+  /* Assume we just "made" the BFD, and fake it.  */
+  memset (sb, 0, sizeof (*sb));
+  time (&sb->st_mtime);
+  sb->st_uid = getuid ();
+  sb->st_gid = getgid ();
+  sb->st_mode = 0644;
+  sb->st_size = bim->size;
+  return 0;
+}
+
+static const struct bfd_iovec bim_iovec = {
+  &bim_bread, &bim_bwrite, &bim_btell, &bim_bseek,
+  &bim_bclose, &bim_bflush, &bim_bstat
+};
+
+/*
+INTERNAL_FUNCTION
+	_bfd_in_memory
+
+SYNOPSIS
+        bfd_boolean _bfd_in_memory (bfd *abfd, flagword flags,
+	                            void *buffer, bfd_size_type size);
+
+DESCRIPTION
+
+        Convert @var{abfd} into a memory <<bfd> containing @var{size}
+        bytes of data at @var{buffer}.  If @var{buffer} is NULL, make
+        the @var{abfd} writeable.
+
+*/
+
+int
+_bfd_in_memory (struct bfd *abfd, flagword flags, void *buffer,
+		bfd_size_type size)
+{
+   struct bfd_in_memory *bim;
+
+   bim = ((struct bfd_in_memory *)
+	  bfd_alloc (abfd, (bfd_size_type) sizeof (struct bfd_in_memory)));
+   if (bim == NULL)
+     {
+       bfd_set_error (bfd_error_no_memory);
+       return FALSE;
+     }
+
+   bim->size = size;
+   bim->buffer = buffer;
+   abfd->iostream = bim;
+   abfd->iovec = &bim_iovec;
+   abfd->flags = flags | BFD_IN_MEMORY;
+   abfd->where = 0;
+   if (buffer != 0)
+     abfd->direction = read_direction;
+   else
+     abfd->direction = write_direction;
+   BFD_ASSERT (! abfd->cacheable);
+   return TRUE;
+}
+
+\f
 /* bfd_openw -- open for writing.
    Returns a pointer to a freshly-allocated BFD on success, or NULL.
 
@@ -593,12 +772,7 @@ bfd_close (bfd *abfd)
   if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
     return FALSE;
 
-  /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
-     vector.  */
-  if (!(abfd->flags & BFD_IN_MEMORY))
-    ret = abfd->iovec->bclose (abfd);
-  else
-    ret = 0;
+  ret = abfd->iovec->bclose (abfd);
 
   /* If the file was open for writing and is now executable,
      make it so.  */
@@ -735,15 +909,9 @@ bfd_make_writable (bfd *abfd)
       return FALSE;
     }
 
-  bim = bfd_malloc (sizeof (struct bfd_in_memory));
-  abfd->iostream = bim;
-  /* bfd_bwrite will grow these as needed.  */
-  bim->size = 0;
-  bim->buffer = 0;
-
-  abfd->flags |= BFD_IN_MEMORY;
-  abfd->direction = write_direction;
-  abfd->where = 0;
+  /* bfd_bwrite will grow this as needed.  */
+  if (!_bfd_in_memory (abfd, abfd->flags, NULL, 0))
+    return FALSE;
 
   return TRUE;
 }
Index: xcofflink.c
===================================================================
RCS file: /cvs/src/src/bfd/xcofflink.c,v
retrieving revision 1.33
diff -p -u -r1.33 xcofflink.c
--- xcofflink.c	2 Dec 2003 22:59:59 -0000	1.33
+++ xcofflink.c	30 Apr 2004 21:38:41 -0000
@@ -3230,22 +3230,11 @@ bfd_xcoff_link_generate_rtinit (abfd, in
      const char *fini;
      bfd_boolean rtld;
 {
-  struct bfd_in_memory *bim;
-
-  bim = ((struct bfd_in_memory *)
-	 bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
-  if (bim == NULL)
+  if (!_bfd_in_memory (abfd, 0, NULL, 0))
     return FALSE;
 
-  bim->size = 0;
-  bim->buffer = 0;
-
   abfd->link_next = 0;
   abfd->format = bfd_object;
-  abfd->iostream = (PTR) bim;
-  abfd->flags = BFD_IN_MEMORY;
-  abfd->direction = write_direction;
-  abfd->where = 0;
 
   if (! bfd_xcoff_generate_rtinit (abfd, init, fini, rtld))
     return FALSE;

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [rfa] Add bfd-in-memory io vector
  2004-04-30 22:03 [rfa] Add bfd-in-memory io vector Andrew Cagney
@ 2004-04-30 22:12 ` DJ Delorie
  2004-04-30 23:01   ` Andrew Cagney
  2004-05-01 18:10 ` Andrew Cagney
  1 sibling, 1 reply; 11+ messages in thread
From: DJ Delorie @ 2004-04-30 22:12 UTC (permalink / raw)
  To: cagney; +Cc: binutils


> I've tested this on i386 GNU/Linux with no regressions.  However, given 
> my experience with the previous IOVEC change, I'm not sure how 
> significant that result is :-/

A significant user of the BIM code is Cygwin's DLL stuff, both
creating DLLs (with ld -shared) and linking against them (directly,
not with import libraries).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [rfa] Add bfd-in-memory io vector
  2004-04-30 22:12 ` DJ Delorie
@ 2004-04-30 23:01   ` Andrew Cagney
  0 siblings, 0 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-04-30 23:01 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

>>> I've tested this on i386 GNU/Linux with no regressions.  However, given 
>>> my experience with the previous IOVEC change, I'm not sure how 
>>> significant that result is :-/
> 
> 
> A significant user of the BIM code is Cygwin's DLL stuff, both
> creating DLLs (with ld -shared) and linking against them (directly,
> not with import libraries).

s/A significant/The evil/, as I wrote:

> Note that it doesn't completly consolidate code using "struct bfd_in_memory" as some of it is pretty evil (grep for remaining references to BFD_IN_MEMORY).  I'll do another pass at eliminating more of the BFD_IN_MEMORY references in a follow-up patch. 

I tried to leave that code be.  Not sure how successful I was.

Andrew


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [rfa] Add bfd-in-memory io vector
  2004-04-30 22:03 [rfa] Add bfd-in-memory io vector Andrew Cagney
  2004-04-30 22:12 ` DJ Delorie
@ 2004-05-01 18:10 ` Andrew Cagney
  2004-05-02 13:56   ` Alan Modra
  1 sibling, 1 reply; 11+ messages in thread
From: Andrew Cagney @ 2004-05-01 18:10 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 712 bytes --]

> Hello,
> 
> This adds a bfd-in-memory IO vector to BFD.  Note that it doesn't completly consolidate code using "struct bfd_in_memory" as some of it is pretty evil (grep for remaining references to BFD_IN_MEMORY).  I'll do another pass at eliminating more of the BFD_IN_MEMORY references in a follow-up patch.
> 
> I've tested this on i386 GNU/Linux with no regressions.  However, given my experience with the previous IOVEC change, I'm not sure how significant that result is :-/

Here's a revised patch.  An audit of remaining BFD_IN_MEMORY references 
turned up a likely bug in peicode.h.  This revision includes what I 
think is the necessary change.

The testing comment still applies though.

Ok?
Andrew


[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 16162 bytes --]

	* libbfd-in.h (_bfd_in_memory): Declare.
	* libbfd.h: Re-generate.
	* peicode.h (pe_ILF_build_a_bfd): Call _bfd_in_memory, set
	vars.bim to value returned.
	(ILF_DATA_SIZE): Do not include "bim" in size.
	* opncls.c (bim_bread, bim_bwrite, bim_btell, bim_bflush, bim_bstat) 
	(bim_bseek, bim_bclose, bim_iovec, _bfd_in_memory): Implement BFD
	in memory.
	(bfd_close): Delete bfd-in-memory code.
	(bfd_make_writable): Use _bfd_in_memory.
	* bfdio.c (bfd_bread, bfd_bwrite, bfd_tell, bfd_flush, bfd_stat) 
	(bfd_seek, bfd_get_size): Delete bfd-in-memory code.
	* elfcode.h (bfd_from_remote_memory): Use _bfd_in_memory.
	* xcofflink.c (bfd_xcoff_link_generate_rtinit): Ditto.
	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Ditto.
 
Index: bfdio.c
===================================================================
RCS file: /cvs/src/src/bfd/bfdio.c,v
retrieving revision 1.6
diff -p -u -r1.6 bfdio.c
--- bfdio.c	21 Apr 2004 17:05:11 -0000	1.6
+++ bfdio.c	1 May 2004 18:00:59 -0000
@@ -97,7 +97,6 @@ DESCRIPTION
 
 */
 
-
 /* Return value is amount read.  */
 
 bfd_size_type
@@ -105,26 +104,6 @@ bfd_bread (void *ptr, bfd_size_type size
 {
   size_t nread;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    {
-      struct bfd_in_memory *bim;
-      bfd_size_type get;
-
-      bim = abfd->iostream;
-      get = size;
-      if (abfd->where + get > bim->size)
-	{
-	  if (bim->size < (bfd_size_type) abfd->where)
-	    get = 0;
-	  else
-	    get = bim->size - abfd->where;
-	  bfd_set_error (bfd_error_file_truncated);
-	}
-      memcpy (ptr, bim->buffer + abfd->where, (size_t) get);
-      abfd->where += get;
-      return get;
-    }
-
   nread = abfd->iovec->bread (abfd, ptr, size);
   if (nread != (size_t) -1)
     abfd->where += nread;
@@ -137,33 +116,6 @@ bfd_bwrite (const void *ptr, bfd_size_ty
 {
   size_t nwrote;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    {
-      struct bfd_in_memory *bim = abfd->iostream;
-      size = (size_t) size;
-      if (abfd->where + size > bim->size)
-	{
-	  bfd_size_type newsize, oldsize;
-
-	  oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	  bim->size = abfd->where + size;
-	  /* Round up to cut down on memory fragmentation */
-	  newsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	  if (newsize > oldsize)
-	    {
-	      bim->buffer = bfd_realloc (bim->buffer, newsize);
-	      if (bim->buffer == 0)
-		{
-		  bim->size = 0;
-		  return 0;
-		}
-	    }
-	}
-      memcpy (bim->buffer + abfd->where, ptr, (size_t) size);
-      abfd->where += size;
-      return size;
-    }
-
   nwrote = abfd->iovec->bwrite (abfd, ptr, size);
   if (nwrote != (size_t) -1)
     abfd->where += nwrote;
@@ -182,9 +134,6 @@ bfd_tell (bfd *abfd)
 {
   file_ptr ptr;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    return abfd->where;
-
   ptr = abfd->iovec->btell (abfd);
 
   if (abfd->my_archive)
@@ -196,8 +145,6 @@ bfd_tell (bfd *abfd)
 int
 bfd_flush (bfd *abfd)
 {
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    return 0;
   return abfd->iovec->bflush (abfd);
 }
 
@@ -208,9 +155,6 @@ bfd_stat (bfd *abfd, struct stat *statbu
 {
   int result;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    abort ();
-
   result = abfd->iovec->bstat (abfd, statbuf);
   if (result < 0)
     bfd_set_error (bfd_error_system_call);
@@ -234,47 +178,6 @@ bfd_seek (bfd *abfd, file_ptr position, 
   if (direction == SEEK_CUR && position == 0)
     return 0;
 
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    {
-      struct bfd_in_memory *bim;
-
-      bim = abfd->iostream;
-
-      if (direction == SEEK_SET)
-	abfd->where = position;
-      else
-	abfd->where += position;
-
-      if (abfd->where > bim->size)
-	{
-	  if ((abfd->direction == write_direction) ||
-	      (abfd->direction == both_direction))
-	    {
-	      bfd_size_type newsize, oldsize;
-	      oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	      bim->size = abfd->where;
-	      /* Round up to cut down on memory fragmentation */
-	      newsize = (bim->size + 127) & ~(bfd_size_type) 127;
-	      if (newsize > oldsize)
-	        {
-		  bim->buffer = bfd_realloc (bim->buffer, newsize);
-		  if (bim->buffer == 0)
-		    {
-		      bim->size = 0;
-		      return -1;
-		    }
-	        }
-	    }
-	  else
-	    {
-	      abfd->where = bim->size;
-	      bfd_set_error (bfd_error_file_truncated);
-	      return -1;
-	    }
-	}
-      return 0;
-    }
-
   if (abfd->format != bfd_archive && abfd->my_archive == 0)
     {
 #if 0
@@ -407,9 +310,6 @@ long
 bfd_get_size (bfd *abfd)
 {
   struct stat buf;
-
-  if ((abfd->flags & BFD_IN_MEMORY) != 0)
-    return ((struct bfd_in_memory *) abfd->iostream)->size;
 
   if (abfd->iovec->bstat (abfd, &buf) != 0)
     return 0;
Index: coff-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-alpha.c,v
retrieving revision 1.20
diff -p -u -r1.20 coff-alpha.c
--- coff-alpha.c	30 Apr 2004 14:23:39 -0000	1.20
+++ coff-alpha.c	1 May 2004 18:01:00 -0000
@@ -2086,7 +2086,6 @@ alpha_ecoff_get_elt_at_filepos (archive,
   bfd_byte ab[8];
   bfd_size_type size;
   bfd_byte *buf, *p;
-  struct bfd_in_memory *bim;
 
   nbfd = _bfd_get_elt_at_filepos (archive, filepos);
   if (nbfd == NULL)
@@ -2181,19 +2180,11 @@ alpha_ecoff_get_elt_at_filepos (archive,
     }
 
   /* Now the uncompressed file contents are in buf.  */
-  bim = ((struct bfd_in_memory *)
-	 bfd_alloc (nbfd, (bfd_size_type) sizeof (struct bfd_in_memory)));
-  if (bim == NULL)
+  if (!_bfd_in_memory (nbfd, nbfd->flags, buf, size))
     goto error_return;
-  bim->size = size;
-  bim->buffer = buf;
 
   nbfd->mtime_set = TRUE;
   nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10);
-
-  nbfd->flags |= BFD_IN_MEMORY;
-  nbfd->iostream = (PTR) bim;
-  BFD_ASSERT (! nbfd->cacheable);
 
   return nbfd;
 
Index: elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.55
diff -p -u -r1.55 elfcode.h
--- elfcode.h	22 Apr 2004 14:45:31 -0000	1.55
+++ elfcode.h	1 May 2004 18:01:00 -0000
@@ -1690,28 +1690,22 @@ NAME(_bfd_elf,bfd_from_remote_memory)
   memcpy (contents, &x_ehdr, sizeof x_ehdr);
 
   /* Now we have a memory image of the ELF file contents.  Make a BFD.  */
-  bim = bfd_malloc (sizeof (struct bfd_in_memory));
-  if (bim == NULL)
+  nbfd = _bfd_new_bfd ();
+  if (nbfd == NULL)
     {
       free (contents);
       bfd_set_error (bfd_error_no_memory);
       return NULL;
     }
-  nbfd = _bfd_new_bfd ();
-  if (nbfd == NULL)
+  if (!_bfd_in_memory (nbfd, 0, contents, contents_size))
     {
-      free (bim);
       free (contents);
+      bfd_close (nbfd);
       bfd_set_error (bfd_error_no_memory);
       return NULL;
     }
   nbfd->filename = "<in-memory>";
   nbfd->xvec = templ->xvec;
-  bim->size = contents_size;
-  bim->buffer = contents;
-  nbfd->iostream = bim;
-  nbfd->flags = BFD_IN_MEMORY;
-  nbfd->direction = read_direction;
   nbfd->mtime = time (NULL);
   nbfd->mtime_set = TRUE;
 
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.33
diff -p -u -r1.33 libbfd-in.h
--- libbfd-in.h	30 Apr 2004 14:23:39 -0000	1.33
+++ libbfd-in.h	1 May 2004 18:01:00 -0000
@@ -50,6 +50,9 @@ struct bfd_in_memory
   bfd_byte *buffer;
 };
 
+struct bfd_in_memory *_bfd_in_memory (struct bfd *abfd, flagword flags,
+				      void *buffer, bfd_size_type size);
+
 /* tdata for an archive.  For an input archive, cache
    needs to be free()'d.  For an output archive, symdefs do.  */
 
Index: opncls.c
===================================================================
RCS file: /cvs/src/src/bfd/opncls.c,v
retrieving revision 1.23
diff -p -u -r1.23 opncls.c
--- opncls.c	23 Apr 2004 00:22:57 -0000	1.23
+++ opncls.c	1 May 2004 18:01:00 -0000
@@ -1,7 +1,7 @@
 /* opncls.c -- open and close a BFD.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
-   2001, 2002, 2003
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Written by Cygnus Support.
 
@@ -501,6 +501,187 @@ bfd_openr_iovec (const char *filename, c
   return nbfd;
 }
 \f
+
+
+/* BFD in memory.  */
+
+static file_ptr
+bim_btell (struct bfd *abfd)
+{
+  return abfd->where;
+}
+
+static int
+bim_bseek (struct bfd *abfd, file_ptr offset, int whence)
+{
+  struct bfd_in_memory *bim;
+
+  bim = abfd->iostream;
+      
+  if (whence == SEEK_SET)
+    abfd->where = offset;
+  else
+    abfd->where += offset;
+  
+  if (abfd->where > bim->size)
+    {
+      if ((abfd->direction == write_direction) ||
+	  (abfd->direction == both_direction))
+	{
+	  bfd_size_type newsize, oldsize;
+	  oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
+	  bim->size = abfd->where;
+	  /* Round up to cut down on memory fragmentation */
+	  newsize = (bim->size + 127) & ~(bfd_size_type) 127;
+	  if (newsize > oldsize)
+	    {
+	      bim->buffer = bfd_realloc (bim->buffer, newsize);
+	      if (bim->buffer == 0)
+		{
+		  bim->size = 0;
+		  return -1;
+		}
+	    }
+	}
+      else
+	{
+	  abfd->where = bim->size;
+	  bfd_set_error (bfd_error_file_truncated);
+	  return -1;
+	}
+    }
+  return 0;
+}
+
+static file_ptr
+bim_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
+{
+  struct bfd_in_memory *bim;
+  bfd_size_type get;
+  
+  bim = abfd->iostream;
+  get = nbytes;
+  if (abfd->where + get > bim->size)
+    {
+      if (bim->size < (bfd_size_type) abfd->where)
+	get = 0;
+      else
+	get = bim->size - abfd->where;
+    }
+  memcpy (buf, bim->buffer + abfd->where, (size_t) get);
+  abfd->where += get;
+  return get;
+}
+
+static file_ptr
+bim_bwrite (struct bfd *abfd, const void *where, file_ptr nbytes)
+{
+  struct bfd_in_memory *bim = abfd->iostream;
+  size_t size;
+
+  size = (size_t) nbytes;
+  if (abfd->where + size > bim->size)
+    {
+      bfd_size_type newsize, oldsize;
+      
+      oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
+      bim->size = abfd->where + size;
+      /* Round up to cut down on memory fragmentation */
+      newsize = (bim->size + 127) & ~(bfd_size_type) 127;
+      if (newsize > oldsize)
+	{
+	  bim->buffer = bfd_realloc (bim->buffer, newsize);
+	  if (bim->buffer == 0)
+	    {
+	      bim->size = 0;
+	      return 0;
+	    }
+	}
+    }
+  memcpy (bim->buffer + abfd->where, where, size);
+  abfd->where += size;
+  return size;
+}
+
+static int
+bim_bclose (struct bfd *abfd ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+static int
+bim_bflush (struct bfd *abfd ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+static int
+bim_bstat (struct bfd *abfd, struct stat *sb)
+{
+  struct bfd_in_memory *bim = abfd->iostream;
+
+  /* Assume we just "made" the BFD, and fake it.  */
+  memset (sb, 0, sizeof (*sb));
+  time (&sb->st_mtime);
+  sb->st_uid = getuid ();
+  sb->st_gid = getgid ();
+  sb->st_mode = 0644;
+  sb->st_size = bim->size;
+  return 0;
+}
+
+static const struct bfd_iovec bim_iovec = {
+  &bim_bread, &bim_bwrite, &bim_btell, &bim_bseek,
+  &bim_bclose, &bim_bflush, &bim_bstat
+};
+
+/*
+INTERNAL_FUNCTION
+	_bfd_in_memory
+
+SYNOPSIS
+        struct bfd_in_memory *_bfd_in_memory (bfd *abfd, flagword flags,
+	                                      void *buffer,
+					      bfd_size_type size);
+
+DESCRIPTION
+
+        Convert @var{abfd} into a memory <<bfd> containing @var{size}
+        bytes of data at @var{buffer}.  If @var{buffer} is NULL, make
+        the @var{abfd} writeable.  Return a pointer to the <<struct
+        bfd_in_memory>>, or NULL if there is an error.
+
+*/
+
+struct bfd_in_memory *
+_bfd_in_memory (struct bfd *abfd, flagword flags, void *buffer,
+		bfd_size_type size)
+{
+   struct bfd_in_memory *bim;
+
+   bim = ((struct bfd_in_memory *)
+	  bfd_alloc (abfd, (bfd_size_type) sizeof (struct bfd_in_memory)));
+   if (bim == NULL)
+     {
+       bfd_set_error (bfd_error_no_memory);
+       return NULL;
+     }
+
+   bim->size = size;
+   bim->buffer = buffer;
+   abfd->iostream = bim;
+   abfd->iovec = &bim_iovec;
+   abfd->flags = flags | BFD_IN_MEMORY;
+   abfd->where = 0;
+   if (buffer != 0)
+     abfd->direction = read_direction;
+   else
+     abfd->direction = write_direction;
+   BFD_ASSERT (! abfd->cacheable);
+   return bim;
+}
+
+\f
 /* bfd_openw -- open for writing.
    Returns a pointer to a freshly-allocated BFD on success, or NULL.
 
@@ -593,12 +774,7 @@ bfd_close (bfd *abfd)
   if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
     return FALSE;
 
-  /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
-     vector.  */
-  if (!(abfd->flags & BFD_IN_MEMORY))
-    ret = abfd->iovec->bclose (abfd);
-  else
-    ret = 0;
+  ret = abfd->iovec->bclose (abfd);
 
   /* If the file was open for writing and is now executable,
      make it so.  */
@@ -735,15 +911,9 @@ bfd_make_writable (bfd *abfd)
       return FALSE;
     }
 
-  bim = bfd_malloc (sizeof (struct bfd_in_memory));
-  abfd->iostream = bim;
-  /* bfd_bwrite will grow these as needed.  */
-  bim->size = 0;
-  bim->buffer = 0;
-
-  abfd->flags |= BFD_IN_MEMORY;
-  abfd->direction = write_direction;
-  abfd->where = 0;
+  /* bfd_bwrite will grow this as needed.  */
+  if (!_bfd_in_memory (abfd, abfd->flags, NULL, 0))
+    return FALSE;
 
   return TRUE;
 }
Index: peicode.h
===================================================================
RCS file: /cvs/src/src/bfd/peicode.h,v
retrieving revision 1.40
diff -p -u -r1.40 peicode.h
--- peicode.h	16 Dec 2003 11:10:42 -0000	1.40
+++ peicode.h	1 May 2004 18:01:01 -0000
@@ -448,8 +448,7 @@ pe_bfd_copy_private_bfd_data (ibfd, obfd
 #define SIZEOF_ILF_SECTIONS     (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
 
 #define ILF_DATA_SIZE				\
-      sizeof (* vars.bim)			\
-    + SIZEOF_ILF_SYMS				\
+      SIZEOF_ILF_SYMS				\
     + SIZEOF_ILF_SYM_TABLE			\
     + SIZEOF_ILF_NATIVE_SYMS			\
     + SIZEOF_ILF_SYM_PTR_TABLE			\
@@ -771,6 +770,7 @@ pe_ILF_build_a_bfd (bfd *           abfd
   asection_ptr             id4, id5, id6 = NULL, text = NULL;
   coff_symbol_type **      imp_sym;
   unsigned int             imp_index;
+  struct bfd_in_memory	   bim;
 
   /* Decode and verify the types field of the ILF structure.  */
   import_type = types & 0x3;
@@ -820,10 +820,8 @@ pe_ILF_build_a_bfd (bfd *           abfd
     return FALSE;
 
   /* Create a bfd_in_memory structure.  */
-  vars.bim = (struct bfd_in_memory *) ptr;
-  vars.bim->buffer = ptr;
-  vars.bim->size   = ILF_DATA_SIZE;
-  ptr += sizeof (* vars.bim);
+  bim.buffer = ptr;
+  bim.size = ILF_DATA_SIZE;
 
   /* Initialise the pointers to regions of the memory and the
      other contents of the pe_ILF_vars structure as well.  */
@@ -1046,9 +1044,10 @@ pe_ILF_build_a_bfd (bfd *           abfd
   /* Switch from file contents to memory contents.  */
   bfd_cache_close (abfd);
 
-  abfd->iostream = (PTR) vars.bim;
-  abfd->flags |= BFD_IN_MEMORY /* | HAS_LOCALS */;
-  abfd->where = 0;
+  vars.bim = _bfd_in_memory (abfd, abfd->flags, vars.bim->buffer,
+			     vars.bim->size);
+  if (vars.bim == NULL)
+    return FALSE;
   obj_sym_filepos (abfd) = 0;
 
   /* Now create a symbol describing the imported value.  */
Index: xcofflink.c
===================================================================
RCS file: /cvs/src/src/bfd/xcofflink.c,v
retrieving revision 1.33
diff -p -u -r1.33 xcofflink.c
--- xcofflink.c	2 Dec 2003 22:59:59 -0000	1.33
+++ xcofflink.c	1 May 2004 18:01:02 -0000
@@ -3230,22 +3230,11 @@ bfd_xcoff_link_generate_rtinit (abfd, in
      const char *fini;
      bfd_boolean rtld;
 {
-  struct bfd_in_memory *bim;
-
-  bim = ((struct bfd_in_memory *)
-	 bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
-  if (bim == NULL)
+  if (!_bfd_in_memory (abfd, 0, NULL, 0))
     return FALSE;
 
-  bim->size = 0;
-  bim->buffer = 0;
-
   abfd->link_next = 0;
   abfd->format = bfd_object;
-  abfd->iostream = (PTR) bim;
-  abfd->flags = BFD_IN_MEMORY;
-  abfd->direction = write_direction;
-  abfd->where = 0;
 
   if (! bfd_xcoff_generate_rtinit (abfd, init, fini, rtld))
     return FALSE;

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [rfa] Add bfd-in-memory io vector
  2004-05-01 18:10 ` Andrew Cagney
@ 2004-05-02 13:56   ` Alan Modra
  2004-05-03 17:19     ` Cygwin tester? Was: " Andrew Cagney
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Modra @ 2004-05-02 13:56 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: binutils

On Sat, May 01, 2004 at 02:10:31PM -0400, Andrew Cagney wrote:
> The testing comment still applies though.

Given DJ's comment, I think you should test this on cygwin before
committing.  If you can't do this yourself, convince someone else
to do so for you.  OK to commit once you've done this.

> --- opncls.c	23 Apr 2004 00:22:57 -0000	1.23
> +++ opncls.c	1 May 2004 18:01:00 -0000
[snip]
> +      if ((abfd->direction == write_direction) ||
> +	  (abfd->direction == both_direction))

I know this was copied from the old code, but please fix the
formatting here and remove the unnecessary parentheses.

> +   bim = ((struct bfd_in_memory *)
> +	  bfd_alloc (abfd, (bfd_size_type) sizeof (struct bfd_in_memory)));

Two unnecessary casts.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Cygwin tester? Was: [rfa] Add bfd-in-memory io vector
  2004-05-02 13:56   ` Alan Modra
@ 2004-05-03 17:19     ` Andrew Cagney
  2004-05-03 22:46       ` Danny Smith
                         ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-05-03 17:19 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

> On Sat, May 01, 2004 at 02:10:31PM -0400, Andrew Cagney wrote:
> 
>>> The testing comment still applies though.
> 
> 
> Given DJ's comment, I think you should test this on cygwin before
> committing.  If you can't do this yourself, convince someone else
> to do so for you.  OK to commit once you've done this.
> 
> 
>>> --- opncls.c	23 Apr 2004 00:22:57 -0000	1.23
>>> +++ opncls.c	1 May 2004 18:01:00 -0000
> 
> [snip]
> 
>>> +      if ((abfd->direction == write_direction) ||
>>> +	  (abfd->direction == both_direction))
> 
> 
> I know this was copied from the old code, but please fix the
> formatting here and remove the unnecessary parentheses.
> 
> 
>>> +   bim = ((struct bfd_in_memory *)
>>> +	  bfd_alloc (abfd, (bfd_size_type) sizeof (struct bfd_in_memory)));

This was copied too :-)

I don't have access to cygwin so I'll need someones help testing this. 
Anyone?

Andrew


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Cygwin tester? Was: [rfa] Add bfd-in-memory io vector
  2004-05-03 17:19     ` Cygwin tester? Was: " Andrew Cagney
@ 2004-05-03 22:46       ` Danny Smith
  2004-05-04 10:00       ` Dave Korn
  2004-05-08  1:13       ` Danny Smith
  2 siblings, 0 replies; 11+ messages in thread
From: Danny Smith @ 2004-05-03 22:46 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: binutils


| > On Sat, May 01, 2004 at 02:10:31PM -0400, Andrew Cagney wrote:
| > 
| >>> The testing comment still applies though.
| > 
| > 
| > Given DJ's comment, I think you should test this on cygwin before
| > committing.  If you can't do this yourself, convince someone else
| > to do so for you.  OK to commit once you've done this.
| > 
| > 

I get this on mingw:

../bfd/.libs/libbfd.a(opncls.o)(.text+0x5ba):opncls.c: undefined reference to `getuid'
../bfd/.libs/libbfd.a(opncls.o)(.text+0x5c6):opncls.c: undefined reference to `getgid'


Configure already tests for getgid,  but not getuid

Addinging this (and appropriate autoconfigury) works on mingw

#ifndef HAVE_GETGID
#define getgid() 0
#endif
#ifndef HAVE_GETUID
#define getuid() 0
#endif

Danny

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Cygwin tester? Was: [rfa] Add bfd-in-memory io vector
  2004-05-03 17:19     ` Cygwin tester? Was: " Andrew Cagney
  2004-05-03 22:46       ` Danny Smith
@ 2004-05-04 10:00       ` Dave Korn
  2004-05-04 17:39         ` Dave Korn
  2004-05-08  1:13       ` Danny Smith
  2 siblings, 1 reply; 11+ messages in thread
From: Dave Korn @ 2004-05-04 10:00 UTC (permalink / raw)
  To: 'Andrew Cagney', 'Alan Modra'; +Cc: binutils

> -----Original Message-----
> From: binutils-owner On Behalf Of Andrew Cagney
> Sent: 03 May 2004 18:20

> > On Sat, May 01, 2004 at 02:10:31PM -0400, Andrew Cagney wrote:
> > 
> >>> The testing comment still applies though.
> > 
> > 
> > Given DJ's comment, I think you should test this on cygwin before
> > committing.  If you can't do this yourself, convince someone else
> > to do so for you.  OK to commit once you've done this.

> I don't have access to cygwin so I'll need someones help 
> testing this. 
> Anyone?
> 
> Andrew


    Hi Andrew,

  I see someone's already doing some mingw testing for you; I could run
cygwin tests if you like.  I'll have to do it as a background job but I
should have some results later today if you still need them.



    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Cygwin tester? Was: [rfa] Add bfd-in-memory io vector
  2004-05-04 10:00       ` Dave Korn
@ 2004-05-04 17:39         ` Dave Korn
  0 siblings, 0 replies; 11+ messages in thread
From: Dave Korn @ 2004-05-04 17:39 UTC (permalink / raw)
  To: 'Andrew Cagney', 'Alan Modra'; +Cc: binutils

> -----Original Message-----
> From: binutils-owner On Behalf Of Dave Korn
> Sent: 04 May 2004 10:59

> > I don't have access to cygwin so I'll need someones help 
> > testing this. 
> > Anyone?
> > 
> > Andrew
> 
> 
>     Hi Andrew,
> 
>   I see someone's already doing some mingw testing for you; I 
> could run
> cygwin tests if you like.  I'll have to do it as a background 
> job but I
> should have some results later today if you still need them.

  As promised.  First, the relevant details:

dk@mace /usr/build/obj> runtest --version
WARNING: Couldn't find the global config file.
Expect version is       5.26
Tcl version is          8.4
Framework version is    1.4.4
dk@mace /usr/build/obj> uname -a
CYGWIN_NT-5.1 mace 1.5.7(0.109/3/2) 2004-01-30 19:32 i686 unknown unknown
Cygwin

  Also, I'm configuring with the following options in both cases:

dk@mace /usr/build/obj-patched> ../src/configure  -v
--prefix=/usr/build/install --disable-nls 2>&1 | tee conf.log

  And I used the slightly revised version of the patch from
http://sources.redhat.com/ml/binutils/2004-05/msg00023.html which avoids a
potential bug in peicode.h, but I didn't bother to fix the spacing as Alan
requested in his reply :-O hope it doesn't affect the results!

  Perhaps worth mentioning that I'm using a slightly old version of the
cygwin dll, but the two sets of results should at least be commensurate with
each other.  First, CVS head:

------------------->begin testsuite results<-------------------
Test Run By dk on Tue May  4 15:17:37 2004
Native configuration is i686-pc-cygwin

		=== binutils tests ===

Schedule of variations:
    unix

XFAIL: simple objcopy of executable

		=== binutils Summary ===

# of expected passes		68
# of expected failures		1
runtest completed at Tue May  4 15:17:52 2004

Test Run By dk on Tue May  4 15:17:55 2004
Native configuration is i686-pc-cygwin

		=== gas tests ===

Schedule of variations:
    unix

FAIL: i386 pcrel reloc

		=== gas Summary ===

# of expected passes		47
# of unexpected failures	1
../as-new 20040504

runtest completed at Tue May  4 15:18:08 2004

Test Run By dk on Tue May  4 15:19:18 2004
Native configuration is i686-pc-cygwin

		=== ld tests ===

Schedule of variations:
    unix

FAIL: linking shared lib
FAIL: bootstrap
FAIL: bootstrap with strip
FAIL: bootstrap with --static
FAIL: bootstrap with --traditional-format
FAIL: bootstrap with --no-keep-memory
FAIL: bootstrap with --relax
FAIL: cdtest with -Ur
FAIL: NOCROSSREFS 2
FAIL: ld-scripts/provide-1
XFAIL: ld-scripts/provide-3
XFAIL: S-records
XFAIL: S-records with constructors

		=== ld Summary ===

# of expected passes		22
# of unexpected failures	10
# of expected failures		3
/usr/build/obj/ld/ld-new 20040504

runtest completed at Tue May  4 15:19:47 2004

Test Run By dk on Tue May  4 15:20:56 2004
Native configuration is i686-pc-cygwin

		=== winsup tests ===

setting trap for SIGTERM to terminated
setting trap for SIGINT to interrupted by user
setting trap for SIGQUIT to interrupted by user
setting trap for SIGSEGV to segmentation violation
dirlist is /artimi/swtools/windows/share/dejagnu/baseboards
pushing config for build, name is mace
dirlist is /artimi/swtools/windows/share/dejagnu/baseboards
pushing config for host, name is mace
Schedule of variations:
    unix

FAIL: msgtest.c (execute)
FAIL: semtest.c (execute)
FAIL: shmtest.c (execute)
XFAIL: ltp/dup03.c (execute)
XFAIL: ltp/dup05.c (execute)
XFAIL: ltp/fcntl05.c (execute)
XFAIL: ltp/fcntl07B.c (execute)
XFAIL: ltp/lseek04.c (execute)
XFAIL: ltp/select03.c (execute)
XFAIL: ltp/setgroups01.c (execute)
XFAIL: ltp/setuid02.c (execute)
XFAIL: ltp/ulimit01.c (compile)
XFAIL: ltp/unlink06.c (execute)
XFAIL: ltp/unlink08.c (execute)
XFAIL: samples/sample-fail.c (execute)
XFAIL: samples/sample-miscompile.c (compile)

		=== winsup Summary ===

# of expected passes		265
# of unexpected failures	3
# of expected failures		13

Binary file
/usr/build/obj/i686-pc-cygwin/winsup/testsuite/../cygwin/cygwin0.dll matches

CYGWIN=ntsec smbntsec notty

runtest completed at Tue May  4 15:34:07 2004
------------------->end testsuite results<-------------------

  Which you'll notice agrees exactly with the results posted earlier today
at http://sources.redhat.com/ml/binutils/2004-05/msg00070.html despite not
even using quite the same cygwin version.

  And now CVS HEAD plus the bfd_in_memory patch: (verified I correctly
applied it by running cvs diff -pu and then diffing the results from that
with the diffs.txt attachment from the original post: only lines with
datestamps were changed, and the ChangeLog entry wasn't there of course)

------------------->begin testsuite results<-------------------

Test Run By dk on Tue May  4 17:18:56 2004
Native configuration is i686-pc-cygwin

		=== binutils tests ===

Schedule of variations:
    unix

Running target unix

XFAIL: simple objcopy of executable

		=== binutils Summary ===

# of expected passes		68
# of expected failures		1
runtest completed at Tue May  4 17:19:10 2004

Test Run By dk on Tue May  4 17:19:13 2004
Native configuration is i686-pc-cygwin

		=== gas tests ===

Schedule of variations:
    unix

Running target unix

FAIL: i386 pcrel reloc

		=== gas Summary ===

# of expected passes		47
# of unexpected failures	1
../as-new 20040504

runtest completed at Tue May  4 17:19:24 2004

Test Run By dk on Tue May  4 17:19:56 2004
Native configuration is i686-pc-cygwin

		=== ld tests ===

Schedule of variations:
    unix

Running target unix

FAIL: linking shared lib
FAIL: bootstrap
FAIL: bootstrap with strip
FAIL: bootstrap with --static
FAIL: bootstrap with --traditional-format
FAIL: bootstrap with --no-keep-memory
FAIL: bootstrap with --relax
FAIL: cdtest with -Ur
FAIL: NOCROSSREFS 2
FAIL: ld-scripts/provide-1
XFAIL: ld-scripts/provide-3
XFAIL: S-records
XFAIL: S-records with constructors

		=== ld Summary ===

# of expected passes		22
# of unexpected failures	10
# of expected failures		3
/usr/build/obj-patched/ld/ld-new 20040504

runtest completed at Tue May  4 17:20:17 2004

Test Run By dk on Tue May  4 17:21:04 2004
Native configuration is i686-pc-cygwin

		=== winsup tests ===

setting trap for SIGTERM to terminated
setting trap for SIGINT to interrupted by user
setting trap for SIGQUIT to interrupted by user
setting trap for SIGSEGV to segmentation violation
dirlist is /artimi/swtools/windows/share/dejagnu/baseboards
pushing config for build, name is mace
dirlist is /artimi/swtools/windows/share/dejagnu/baseboards
pushing config for host, name is mace
Schedule of variations:
    unix

target is unix

FAIL: msgtest.c (execute)
FAIL: semtest.c (execute)
FAIL: shmtest.c (execute)
XFAIL: ltp/dup03.c (execute)
XFAIL: ltp/dup05.c (execute)
XFAIL: ltp/fcntl05.c (execute)
XFAIL: ltp/fcntl07B.c (execute)
XFAIL: ltp/lseek04.c (execute)
XFAIL: ltp/select03.c (execute)
XFAIL: ltp/setgroups01.c (execute)
XFAIL: ltp/setuid02.c (execute)
XFAIL: ltp/ulimit01.c (compile)
XFAIL: ltp/unlink06.c (execute)
XFAIL: ltp/unlink08.c (execute)
XFAIL: samples/sample-fail.c (execute)
XFAIL: samples/sample-miscompile.c (compile)

		=== winsup Summary ===

# of expected passes		265
# of unexpected failures	3
# of expected failures		13

Binary file
/usr/build/obj-patched/i686-pc-cygwin/winsup/testsuite/../cygwin/cygwin0.dll
matches

CYGWIN=ntsec smbntsec notty

runtest completed at Tue May  4 17:33:20 2004

------------------->end testsuite results<-------------------

  Hey!  Looks like no regressions to me.  Just to be completely sure I've
installed the new patched binutils and rerun just the winsup build-and-test
using them: 

                === winsup Summary ===

# of expected passes            265
# of unexpected failures        3
# of expected failures          13

Binary file
/usr/build/obj-patched/i686-pc-cygwin/winsup/testsuite/../cygwin/cygwin0.dll
matches

CYGWIN=ntsec smbntsec notty

[ To be completely certain the new as and ld were being used, I copied and
pasted one of the build commands from the test output, adding the -v flag;
then I did the same with the resulting collect2 command, and saw it was
correctly invoking /usr/build/install/bin/ld ]

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....
 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Cygwin tester? Was: [rfa] Add bfd-in-memory io vector
  2004-05-03 17:19     ` Cygwin tester? Was: " Andrew Cagney
  2004-05-03 22:46       ` Danny Smith
  2004-05-04 10:00       ` Dave Korn
@ 2004-05-08  1:13       ` Danny Smith
  2 siblings, 0 replies; 11+ messages in thread
From: Danny Smith @ 2004-05-08  1:13 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: binutils


----- Original Message -----
From: "Andrew Cagney"

| > On Sat, May 01, 2004 at 02:10:31PM -0400, Andrew Cagney wrote:
| >
| >>> The testing comment still applies though.
| >
| >
| > Given DJ's comment, I think you should test this on cygwin before
| > committing.  If you can't do this yourself, convince someone else
| > to do so for you.  OK to commit once you've done this.
| >
|

Hi,
I've run into another pe-dll problem with your proposed patch (after modifying to protect
against
bread-ing NULL files)
When building a dll import lib, I get this error from  coffcode.h:styp_to_sec_flags:

D:\develop>gcc -shared -ofoo.dll -Wl,--out-implib,libfoo.a foo.c
Creating library file: libfoo.a
D:\MINGW\BIN\..\lib\gcc\mingw32\3.4.0\..\..\..\..\mingw32\bin\ld.exe: d000000.o ():
Section flag STYP_GROUP (0x4) ignored
D:\MINGW\BIN\..\lib\gcc\mingw32\3.4.0\..\..\..\..\mingw32\bin\ld.exe: d000001.o ():
Section flag STYP_GROUP (0x4) ignored
D:\MINGW\BIN\..\lib\gcc\mingw32\3.4.0\..\..\..\..\mingw32\bin\ld.exe: d000002.o ():
Section flag STYP_GROUP (0x4) ignored
D:\MINGW\BIN\..\lib\gcc\mingw32\3.4.0\..\..\..\..\mingw32\bin\ld.exe: d000002.o ():
Section flag STYP_GROUP (0x4) ignored
D:\MINGW\BIN\..\lib\gcc\mingw32\3.4.0\..\..\..\..\mingw32\bin\ld.exe: d000000.o ():
Section flag STYP_GROUP (0x4) ignored
D:\MINGW\BIN\..\lib\gcc\mingw32\3.4.0\..\..\..\..\mingw32\bin\ld.exe: d000001.o ():
Section flag STYP_GROUP (0x4) ignored

and a broken import lib is created

The STYP_GROUP flag is not set anywhere AFAICT.

The d00000[012].o files are created by make_head, make_one, and
make_tail, respectively, in ld/pe-dll.c.

Danny
.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Cygwin tester? Was: [rfa] Add bfd-in-memory io vector
  2004-05-05 11:09 ` Re[3]: " Danny Smith
@ 2004-05-05 15:57   ` Andrew Cagney
  0 siblings, 0 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-05-05 15:57 UTC (permalink / raw)
  To: Danny Smith, dk; +Cc: binutils

Dave, Danny, thanks!

> From: "Danny Smith" 
> | 
> | From: "Danny Smith"
> | 
> | | 
> | | | > On Sat, May 01, 2004 at 02:10:31PM -0400, Andrew Cagney wrote:
> | | | > 
> | | | >>> The testing comment still applies though.
> | | | > 
> | | | > 
> | | | > Given DJ's comment, I think you should test this on cygwin before
> | | | > committing.  If you can't do this yourself, convince someone else
> | | | > to do so for you.  OK to commit once you've done this.
> | | | > 
> 
> Hi,
> 
> Although the patchset works fine (if I add the checks for HAVE_GET[GU]ID) 
> when building .exe files on pe targets, it fails when building dll's 
> (segfault in bfd/bfdio.c:bfd_bread when forwarding args to iovec->bread)  

I'll add this to the patch.

> With binutils built with CFLAGS="-g -O2", gcc-3.4.0, mingw32:
> 
> cat > foo.c
> int foo = 1;
> ^Z
> gcc -shared -ofoo.dll foo.c
> 
> raises the segfault in bfd_bread. 
> 
> Actually, the above testcase fails since your 21-April patch.
> 
> The problem occurs when pe-dll.c code calls bread with a NULL file, asking for zero bytes
> (see comment in cache.c:cache_bread). 
> 
> The problem can be avoided by doing the cache_bread FIXME in bfd_bread, ie:
> 
> *** bfdio.c.cagney Mon May 03 10:02:13 2004
> --- bfdio.c Tue May 04 11:26:40 2004
> *************** bfd_bread (void *ptr, bfd_size_type size
> *** 104,109 ****
> --- 104,113 ----
>   {
>     size_t nread;
>   
> +   /*  See FIXME in cache.c:cache_bread(). */
> +   if (size == 0)
> +     return 0;
> + 
>     nread = abfd->iovec->bread (abfd, ptr, size);
>     if (nread != (size_t) -1)
>       abfd->where += nread;

Outch, thanks.  I think I'll move the fixme as well as a separate patch.

> With above patch, simple dll build is okay. 
> But this looks a bit strange in  peicode.h:pe_ILF_build_a_bfd()
> 
> +  vars.bim = _bfd_in_memory (abfd, abfd->flags, vars.bim->buffer,
> +        vars.bim->size);

Oops, yes.

Andrew

> Should that be:
> 
> vars.bim = _bfd_in_memory (abfd, abfd->flags, bim.buffer, bim.size);
> 
> 
> Danny


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-05-08  1:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-30 22:03 [rfa] Add bfd-in-memory io vector Andrew Cagney
2004-04-30 22:12 ` DJ Delorie
2004-04-30 23:01   ` Andrew Cagney
2004-05-01 18:10 ` Andrew Cagney
2004-05-02 13:56   ` Alan Modra
2004-05-03 17:19     ` Cygwin tester? Was: " Andrew Cagney
2004-05-03 22:46       ` Danny Smith
2004-05-04 10:00       ` Dave Korn
2004-05-04 17:39         ` Dave Korn
2004-05-08  1:13       ` Danny Smith
2004-05-03 22:48 Re[2]: " Danny Smith
2004-05-05 11:09 ` Re[3]: " Danny Smith
2004-05-05 15:57   ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).