public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-threaded-dwarf: BFD minimal thread-awareness. Unbreak the cache, update gdb to follow.
@ 2010-06-07 22:12 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2010-06-07 22:12 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-threaded-dwarf has been updated
       via  c96a2a771a3864b356a6f39b8f11da6e53bcbacd (commit)
       via  574ec047bc80357c701bf8e5cb907e24f9d3961c (commit)
      from  66baf61458b08c72cf92ef88af4261805bde740f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c96a2a771a3864b356a6f39b8f11da6e53bcbacd
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Jun 7 16:11:10 2010 -0600

    BFD minimal thread-awareness.
    Unbreak the cache, update gdb to follow.

commit 574ec047bc80357c701bf8e5cb907e24f9d3961c
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Jun 7 12:39:36 2010 -0600

    Add configury; support no-threads case

-----------------------------------------------------------------------

Summary of changes:
 bfd/bfd-in2.h       |   25 +++-
 bfd/cache.c         |  221 ++++++++++++++++++++++++++-----
 bfd/doc/Makefile.am |    6 +-
 bfd/doc/Makefile.in |    6 +-
 bfd/libbfd.h        |    2 +
 gdb/config.in       |    6 +
 gdb/configure       |   61 ++++++++-
 gdb/configure.ac    |    6 +-
 gdb/taskpool.c      |  374 ++++++++++++++++++++++++++++++++++++++++++---------
 9 files changed, 597 insertions(+), 110 deletions(-)

First 500 lines of diff:
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index c90ac2d..ef4f907 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1,8 +1,8 @@
 /* DO NOT EDIT!  -*- buffer-read-only: t -*-  This file is automatically 
    generated from "bfd-in.h", "init.c", "opncls.c", "libbfd.c", 
    "bfdio.c", "bfdwin.c", "section.c", "archures.c", "reloc.c", 
-   "syms.c", "bfd.c", "archive.c", "corefile.c", "targets.c", "format.c", 
-   "linker.c", "simple.c" and "compress.c".
+   "syms.c", "bfd.c", "archive.c", "corefile.c", "cache.c", "targets.c", 
+   "format.c", "linker.c", "simple.c" and "compress.c".
    Run "make headers" in your build bfd/ to regenerate.  */
 
 /* Main header file for the bfd library -- portable access to object files.
@@ -2574,6 +2574,8 @@ relocation types already defined.  */
   BFD_RELOC_SPU_PPU32,
   BFD_RELOC_SPU_PPU64,
   BFD_RELOC_SPU_ADD_PIC,
+  BFD_RELOC_SPU_PIC18,
+  BFD_RELOC_SPU_STUB,
 
 /* Alpha ECOFF and ELF relocations.  Some of these treat the symbol or
 "addend" in some special way.
@@ -5315,6 +5317,25 @@ bfd_boolean core_file_matches_executable_p
 bfd_boolean generic_core_file_matches_executable_p
    (bfd *core_bfd, bfd *exec_bfd);
 
+/* Extracted from cache.c.  */
+bfd_boolean bfd_cache_close_all (void);
+
+struct bfd_thread_info
+{
+  /* Return the ID of the current thread.  Should never return NULL.  */
+  void *(*self) (void);
+  /* Create a mutex and return it.  */
+  void *(*create_mutex) (void);
+  /* Lock a mutex.  */
+  void (*lock_mutex) (void *);
+  /* Unlock a mutex.  */
+  void (*unlock_mutex) (void *);
+};
+
+void bfd_init_threads (const struct bfd_thread_info *info);
+
+void bfd_thread_exit (void);
+
 /* Extracted from targets.c.  */
 #define BFD_SEND(bfd, message, arglist) \
   ((*((bfd)->xvec->message)) arglist)
diff --git a/bfd/cache.c b/bfd/cache.c
index a1fbc1f..2156d8b 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -1,7 +1,7 @@
 /* BFD library -- caching of file descriptors.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002,
-   2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
    Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
@@ -50,8 +50,6 @@ SUBSECTION
 #include <sys/mman.h>
 #endif
 
-#include <pthread.h>
-
 /* In some cases we can optimize cache operation when reopening files.
    For instance, a flush is entirely unnecessary if the file is already
    closed, so a flush would use CACHE_NO_OPEN.  Similarly, a seek using
@@ -82,12 +80,40 @@ static int open_files;
 
 static bfd *bfd_last_cache = NULL;
 
+/* Forward declaration.  */
+
+static struct bfd_thread_info dummy_thread_vector;
+
+/* The threading dispatch vector.  If threading is not enabled, this
+   points to dummy_thread_vector.  */
+
+static const struct bfd_thread_info *thread_vector = &dummy_thread_vector;
+
 /* The lock held when accessing the cache or modifying any
-   cache-related fields of a cached BFD.  This approach is only
-   semi-complete because we may have more than BFD_CACHE_MAX_OPEN
-   threads working at the same time -- leading to failure.  */
+   cache-related fields of a cached BFD.  */
+
+static void *cache_lock;
+
+/* The most recently accessed BFDs for each thread are kept in a list
+   of this type.  */
+
+struct thread_map_entry
+{
+  /* The thread ID.  */
+  void *thread;
+  /* The BFD.  */
+  bfd *abfd;
+  /* Link.  */
+  struct thread_map_entry *next;
+};
+
+/* The list of all thread_map_entry structures.  */
+
+static struct thread_map_entry *thread_map;
 
-static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
+/* This thread's thread_map_entry.  */
+
+static __thread struct thread_map_entry self_map_entry;
 
 static FILE *bfd_do_open_file (bfd *abfd);
 
@@ -96,6 +122,14 @@ static FILE *bfd_do_open_file (bfd *abfd);
 static void
 insert (bfd *abfd)
 {
+  if (self_map_entry.thread == NULL)
+    {
+      self_map_entry.thread = thread_vector->self ();
+      self_map_entry.next = thread_map;
+      thread_map = &self_map_entry;
+    }
+  self_map_entry.abfd = abfd;
+
   if (bfd_last_cache == NULL)
     {
       abfd->lru_next = abfd;
@@ -162,9 +196,28 @@ close_one (void)
   else
     {
       for (to_kill = bfd_last_cache->lru_prev;
-	   ! to_kill->cacheable;
+	   ;
 	   to_kill = to_kill->lru_prev)
 	{
+	  if (! to_kill->cacheable)
+	    {
+	      struct thread_map_entry *entry;
+	      int found = 0;
+
+	      /* If the BFD is referenced by some thread, skip it.  */
+	      for (entry = thread_map; entry; entry = entry->next)
+		{
+		  if (to_kill == entry->abfd)
+		    {
+		      found = 1;
+		      break;
+		    }
+		}
+
+	      if (!found)
+		break;
+	    }
+
 	  if (to_kill == bfd_last_cache)
 	    {
 	      to_kill = NULL;
@@ -238,12 +291,12 @@ static FILE *
 bfd_cache_lookup (struct bfd *x, enum cache_flag flag)
 {
   FILE *result;
-  pthread_mutex_lock (&cache_lock);
+  thread_vector->lock_mutex (cache_lock);
   if (x == bfd_last_cache)
     result = (FILE *) (bfd_last_cache->iostream);
   else
     result = bfd_cache_lookup_worker (x, flag);
-  pthread_mutex_unlock (&cache_lock);
+  thread_vector->unlock_mutex (cache_lock);
   return result;
 }
 
@@ -475,9 +528,9 @@ bfd_boolean
 bfd_cache_init (bfd *abfd)
 {
   bfd_boolean result;
-  pthread_mutex_lock (&cache_lock);
+  thread_vector->lock_mutex (cache_lock);
   result = bfd_do_cache_init (abfd);
-  pthread_mutex_unlock (&cache_lock);
+  thread_vector->unlock_mutex (cache_lock);
   return result;
 }
 
@@ -515,9 +568,9 @@ bfd_cache_close (bfd *abfd)
 {
   bfd_boolean result;
 
-  pthread_mutex_lock (&cache_lock);
+  thread_vector->lock_mutex (cache_lock);
   result = bfd_cache_do_close (abfd);
-  pthread_mutex_unlock (&cache_lock);
+  thread_vector->unlock_mutex (cache_lock);
   return result;
 }
 
@@ -542,29 +595,14 @@ bfd_cache_close_all ()
 {
   bfd_boolean ret = TRUE;
 
-  pthread_mutex_lock (&cache_lock);
+  thread_vector->lock_mutex (cache_lock);
   while (bfd_last_cache != NULL)
     ret &= bfd_cache_do_close (bfd_last_cache);
-  pthread_mutex_unlock (&cache_lock);
+  thread_vector->unlock_mutex (cache_lock);
 
   return ret;
 }
 
-/*
-INTERNAL_FUNCTION
-	bfd_open_file
-
-SYNOPSIS
-	FILE* bfd_open_file (bfd *abfd);
-
-DESCRIPTION
-	Call the OS to open a file for @var{abfd}.  Return the <<FILE *>>
-	(possibly <<NULL>>) that results from this operation.  Set up the
-	BFD so that future accesses know the file is open. If the <<FILE *>>
-	returned is <<NULL>>, then it won't have been put in the
-	cache, so it won't have to be removed from it.
-*/
-
 static FILE *
 bfd_do_open_file (bfd *abfd)
 {
@@ -635,12 +673,129 @@ bfd_do_open_file (bfd *abfd)
   return (FILE *) abfd->iostream;
 }
 
+/*
+INTERNAL_FUNCTION
+	bfd_open_file
+
+SYNOPSIS
+	FILE* bfd_open_file (bfd *abfd);
+
+DESCRIPTION
+	Call the OS to open a file for @var{abfd}.  Return the <<FILE *>>
+	(possibly <<NULL>>) that results from this operation.  Set up the
+	BFD so that future accesses know the file is open. If the <<FILE *>>
+	returned is <<NULL>>, then it won't have been put in the
+	cache, so it won't have to be removed from it.
+*/
+
 FILE *
 bfd_open_file (bfd *abfd)
 {
   FILE *result;
-  pthread_mutex_lock (&cache_lock);
+  thread_vector->lock_mutex (cache_lock);
   result = bfd_do_open_file (abfd);
-  pthread_mutex_unlock (&cache_lock);
+  thread_vector->unlock_mutex (cache_lock);
   return result;
 }
+
+/*
+SECTION
+	Thread awareness
+
+DESCRIPTION
+	BFD is optionally, and minimally, thread-aware.  The BFD user
+	is generally responsible for ensuring that multiple threads
+	synchronize their access to a BFD.
+
+	The exception to this general rule is the file cache, which
+	must be directly thread-aware to work properly.  When this
+	thread-awareness mode is enabled, the file cache ensures that
+	at least the BFD most recently used by a given thread remains
+	open.
+
+CODE_FRAGMENT
+.
+.struct bfd_thread_info
+.{
+.  {* Return the ID of the current thread.  Should never return NULL.  *}
+.  void *(*self) (void);
+.  {* Create a mutex and return it.  *}
+.  void *(*create_mutex) (void);
+.  {* Lock a mutex.  *}
+.  void (*lock_mutex) (void *);
+.  {* Unlock a mutex.  *}
+.  void (*unlock_mutex) (void *);
+.};
+.
+
+SUBSECTION
+	Thread-awareness functions.
+
+*/
+
+static void *
+dummy_void_star_void (void)
+{
+  return "hi bob";
+}
+
+static void
+dummy_void_void_star (void *ignore ATTRIBUTE_UNUSED)
+{
+}
+
+static struct bfd_thread_info dummy_thread_vector =
+{
+  dummy_void_star_void,
+  dummy_void_star_void,
+  dummy_void_void_star,
+  dummy_void_void_star
+};
+
+/*
+FUNCTION
+	bfd_init_threads
+
+SYNOPSIS
+	void bfd_init_threads (const struct bfd_thread_info *info);
+
+DESCRIPTION
+	Initialize BFD thread-awareness.  @var{info} is used by BFD
+	to perform the minimal synchronization that it needs.
+*/
+void
+bfd_init_threads (const struct bfd_thread_info *info)
+{
+  BFD_ASSERT (thread_vector == &dummy_thread_vector);
+
+  thread_vector = info;
+  cache_lock = thread_vector->create_mutex ();
+}
+
+/*
+FUNCTION
+	bfd_thread_exit
+
+SYNOPSIS
+	void bfd_thread_exit (void);
+
+DESCRIPTION
+	When a thread using BFD exits, it should call this function.
+	This lets BFD clean up any cached state associated with this
+	thread.  If threading is not enabled, or if the thread never
+	used BFD, then this call is not needed.
+*/
+void
+bfd_thread_exit (void)
+{
+  struct thread_map_entry **iter;
+
+  for (iter = &thread_map; *iter; iter = &(*iter)->next)
+    {
+      if (*iter == &self_map_entry)
+	{
+	  *iter = self_map_entry.next;
+	  break;
+	}
+    }
+}
diff --git a/bfd/doc/Makefile.am b/bfd/doc/Makefile.am
index 7476ee5..6dfe16e 100644
--- a/bfd/doc/Makefile.am
+++ b/bfd/doc/Makefile.am
@@ -12,7 +12,7 @@ DOCFILES = aoutx.texi  archive.texi archures.texi \
 	bfdver.texi
 
 PROTOS = archive.p archures.p bfd.p \
-	 core.p format.p \
+	cache.p core.p format.p \
 	bfdio.p bfdwin.p \
 	libbfd.p opncls.p reloc.p \
 	section.p syms.p targets.p  \
@@ -36,7 +36,8 @@ SRCDOC = $(srcdir)/../aoutx.h  $(srcdir)/../archive.c \
 	$(srcdir)/../mmo.c
 
 SRCPROT = $(srcdir)/../archive.c $(srcdir)/../archures.c \
-	$(srcdir)/../bfd.c $(srcdir)/../coffcode.h $(srcdir)/../corefile.c \
+	$(srcdir)/../bfd.c $(srcdir)/../cache.c \
+	$(srcdir)/../coffcode.h $(srcdir)/../corefile.c \
 	$(srcdir)/../format.c $(srcdir)/../libbfd.c \
 	$(srcdir)/../bfdio.c $(srcdir)/../bfdwin.c \
 	$(srcdir)/../opncls.c $(srcdir)/../reloc.c \
@@ -245,6 +246,7 @@ BFD_H_DEP = \
 	$(srcdir)/../bfd.c		\
 	$(srcdir)/../archive.c		\
 	$(srcdir)/../corefile.c		\
+	$(srcdir)/../cache.c		\
 	$(srcdir)/../targets.c		\
 	$(srcdir)/../format.c		\
 	$(srcdir)/../linker.c		\
diff --git a/bfd/doc/Makefile.in b/bfd/doc/Makefile.in
index 9a59e3f..1e392f5 100644
--- a/bfd/doc/Makefile.in
+++ b/bfd/doc/Makefile.in
@@ -280,7 +280,7 @@ DOCFILES = aoutx.texi  archive.texi archures.texi \
 	bfdver.texi
 
 PROTOS = archive.p archures.p bfd.p \
-	 core.p format.p \
+	cache.p core.p format.p \
 	bfdio.p bfdwin.p \
 	libbfd.p opncls.p reloc.p \
 	section.p syms.p targets.p  \
@@ -304,7 +304,8 @@ SRCDOC = $(srcdir)/../aoutx.h  $(srcdir)/../archive.c \
 	$(srcdir)/../mmo.c
 
 SRCPROT = $(srcdir)/../archive.c $(srcdir)/../archures.c \
-	$(srcdir)/../bfd.c $(srcdir)/../coffcode.h $(srcdir)/../corefile.c \
+	$(srcdir)/../bfd.c $(srcdir)/../cache.c \
+	$(srcdir)/../coffcode.h $(srcdir)/../corefile.c \
 	$(srcdir)/../format.c $(srcdir)/../libbfd.c \
 	$(srcdir)/../bfdio.c $(srcdir)/../bfdwin.c \
 	$(srcdir)/../opncls.c $(srcdir)/../reloc.c \
@@ -359,6 +360,7 @@ BFD_H_DEP = \
 	$(srcdir)/../bfd.c		\
 	$(srcdir)/../archive.c		\
 	$(srcdir)/../corefile.c		\
+	$(srcdir)/../cache.c		\
 	$(srcdir)/../targets.c		\
 	$(srcdir)/../format.c		\
 	$(srcdir)/../linker.c		\
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index fa9d187..05af3bc 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -994,6 +994,8 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_SPU_PPU32",
   "BFD_RELOC_SPU_PPU64",
   "BFD_RELOC_SPU_ADD_PIC",
+  "BFD_RELOC_SPU_PIC18",
+  "BFD_RELOC_SPU_STUB",
   "BFD_RELOC_ALPHA_GPDISP_HI16",
   "BFD_RELOC_ALPHA_GPDISP_LO16",
   "BFD_RELOC_ALPHA_GPDISP",
diff --git a/gdb/config.in b/gdb/config.in
index 5414b08..3e91c8c 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -339,6 +339,12 @@
 /* Define if <sys/procfs.h> has pstatus_t. */
 #undef HAVE_PSTATUS_T
 
+/* Define to 1 if you have the `pthread_create' function. */
+#undef HAVE_PTHREAD_CREATE
+
+/* Define to 1 if you have the <pthread.h> header file. */
+#undef HAVE_PTHREAD_H
+
 /* Define if sys/ptrace.h defines the PTRACE_GETFPXREGS request. */
 #undef HAVE_PTRACE_GETFPXREGS
 
diff --git a/gdb/configure b/gdb/configure
index 6b05993..52a84d0 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -8042,6 +8042,63 @@ fi
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_create" >&5
+$as_echo_n "checking for library containing pthread_create... " >&6; }
+if test "${ac_cv_search_pthread_create+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' pthread; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_pthread_create=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-06-07 22:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-07 22:12 [SCM] archer-tromey-threaded-dwarf: BFD minimal thread-awareness. Unbreak the cache, update gdb to follow tromey

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).