aboutsummaryrefslogtreecommitdiff
path: root/bfd/opncls.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/opncls.c')
-rw-r--r--bfd/opncls.c67
1 files changed, 52 insertions, 15 deletions
diff --git a/bfd/opncls.c b/bfd/opncls.c
index b02b137889a1..4457a797cf4e 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -1,6 +1,6 @@
/* opncls.c -- open and close a BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc.
Written by Cygnus Support.
@@ -21,8 +21,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
-#include "bfd.h"
#include "sysdep.h"
+#include "bfd.h"
#include "objalloc.h"
#include "libbfd.h"
#include "libiberty.h"
@@ -115,11 +115,35 @@ _bfd_new_bfd_contained_in (bfd *obfd)
void
_bfd_delete_bfd (bfd *abfd)
{
- bfd_hash_table_free (&abfd->section_htab);
- objalloc_free ((struct objalloc *) abfd->memory);
+ if (abfd->memory)
+ {
+ bfd_hash_table_free (&abfd->section_htab);
+ objalloc_free ((struct objalloc *) abfd->memory);
+ }
free (abfd);
}
+/* Free objalloc memory. */
+
+bfd_boolean
+_bfd_free_cached_info (bfd *abfd)
+{
+ if (abfd->memory)
+ {
+ bfd_hash_table_free (&abfd->section_htab);
+ objalloc_free ((struct objalloc *) abfd->memory);
+
+ abfd->sections = NULL;
+ abfd->section_last = NULL;
+ abfd->outsymbols = NULL;
+ abfd->tdata.any = NULL;
+ abfd->usrdata = NULL;
+ abfd->memory = NULL;
+ }
+
+ return TRUE;
+}
+
/*
SECTION
Opening and closing BFDs
@@ -360,7 +384,10 @@ SYNOPSIS
file_ptr nbytes,
file_ptr offset),
int (*close) (struct bfd *nbfd,
- void *stream));
+ void *stream),
+ int (*stat) (struct bfd *abfd,
+ void *stream,
+ struct stat *sb));
DESCRIPTION
@@ -387,6 +414,10 @@ DESCRIPTION
<<bfd_close>>. @var{close} either succeeds returning 0, or
fails returning -1 (setting <<bfd_error>>).
+ Calls @var{stat} to fill in a stat structure for bfd_stat,
+ bfd_get_size, and bfd_get_mtime calls. @var{stat} returns 0
+ on success, or returns -1 on failure (setting <<bfd_error>>).
+
If <<bfd_openr_iovec>> returns <<NULL>> then an error has
occurred. Possible errors are <<bfd_error_no_memory>>,
<<bfd_error_invalid_target>> and <<bfd_error_system_call>>.
@@ -399,6 +430,7 @@ struct opncls
file_ptr (*pread) (struct bfd *abfd, void *stream, void *buf,
file_ptr nbytes, file_ptr offset);
int (*close) (struct bfd *abfd, void *stream);
+ int (*stat) (struct bfd *abfd, void *stream, struct stat *sb);
file_ptr where;
};
@@ -461,10 +493,15 @@ opncls_bflush (struct bfd *abfd ATTRIBUTE_UNUSED)
}
static int
-opncls_bstat (struct bfd *abfd ATTRIBUTE_UNUSED, struct stat *sb)
+opncls_bstat (struct bfd *abfd, struct stat *sb)
{
+ struct opncls *vec = abfd->iostream;
+
memset (sb, 0, sizeof (*sb));
- return 0;
+ if (vec->stat == NULL)
+ return 0;
+
+ return (vec->stat) (abfd, vec->stream, sb);
}
static const struct bfd_iovec opncls_iovec = {
@@ -483,7 +520,10 @@ bfd_openr_iovec (const char *filename, const char *target,
file_ptr nbytes,
file_ptr offset),
int (*close) (struct bfd *nbfd,
- void *stream))
+ void *stream),
+ int (*stat) (struct bfd *abfd,
+ void *stream,
+ struct stat *sb))
{
bfd *nbfd;
const bfd_target *target_vec;
@@ -515,6 +555,7 @@ bfd_openr_iovec (const char *filename, const char *target,
vec->stream = stream;
vec->pread = pread;
vec->close = close;
+ vec->stat = stat;
nbfd->iovec = &opncls_iovec;
nbfd->iostream = vec;
@@ -1321,6 +1362,7 @@ bfd_create_gnu_debuglink_section (bfd *abfd, const char *filename)
{
asection *sect;
bfd_size_type debuglink_size;
+ flagword flags;
if (abfd == NULL || filename == NULL)
{
@@ -1339,16 +1381,11 @@ bfd_create_gnu_debuglink_section (bfd *abfd, const char *filename)
return NULL;
}
- sect = bfd_make_section (abfd, GNU_DEBUGLINK);
+ flags = SEC_HAS_CONTENTS | SEC_READONLY | SEC_DEBUGGING;
+ sect = bfd_make_section_with_flags (abfd, GNU_DEBUGLINK, flags);
if (sect == NULL)
return NULL;
- if (! bfd_set_section_flags (abfd, sect,
- SEC_HAS_CONTENTS | SEC_READONLY | SEC_DEBUGGING))
- /* XXX Should we delete the section from the bfd ? */
- return NULL;
-
-
debuglink_size = strlen (filename) + 1;
debuglink_size += 3;
debuglink_size &= ~3;