From bc7aac86cdf8938f43bc5b9c6f1ac33c1882cf7b Mon Sep 17 00:00:00 2001
From: David 'Digit' Turner <digit@android.com>
Date: Thu, 25 Nov 2010 18:37:38 +0100
Subject: [PATCH] Proper libthread_db support in gdbserver.

Change-Id: I5ebbb18efe663e7bf24d6147f33cc92f38dea148
---
 gdb-6.6/gdb/gdbserver/acinclude.m4   |    2 +-
 gdb-6.6/gdb/gdbserver/configure      |    2 +-
 gdb-7.1.x/gdb/gdbserver/Makefile.in  |    8 ++++----
 gdb-7.1.x/gdb/gdbserver/configure    |    4 ++--
 gdb-7.1.x/gdb/gdbserver/configure.ac |    4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gdb-6.6/gdb/gdbserver/acinclude.m4 b/gdb-6.6/gdb/gdbserver/acinclude.m4
index aaad2e2..04f023c 100644
--- a/gdb-6.6/gdb/gdbserver/acinclude.m4
+++ b/gdb-6.6/gdb/gdbserver/acinclude.m4
@@ -4,7 +4,7 @@ sinclude(../../bfd/bfd.m4)
 AC_DEFUN([SRV_CHECK_THREAD_DB],
 [AC_CACHE_CHECK([for libthread_db],[srv_cv_thread_db],
  [old_LIBS="$LIBS"
-  LIBS="$LIBS -lthread_db"
+  LIBS="$LIBS -lthread_db -lc"
   AC_TRY_LINK(
   [void ps_pglobal_lookup() {}
    void ps_pdread() {}
diff --git a/gdb-6.6/gdb/gdbserver/configure b/gdb-6.6/gdb/gdbserver/configure
index 9d97888..debb43a 100755
--- a/gdb-6.6/gdb/gdbserver/configure
+++ b/gdb-6.6/gdb/gdbserver/configure
@@ -3657,7 +3657,7 @@ if test "${srv_cv_thread_db+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   old_LIBS="$LIBS"
-  LIBS="$LIBS -lthread_db"
+  LIBS="$LIBS -lthread_db -lc"
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
diff --git a/gdb-7.1.x/gdb/gdbserver/Makefile.in b/gdb-7.1.x/gdb/gdbserver/Makefile.in
index 5bf82e2..bc2ed43 100644
--- a/gdb-7.1.x/gdb/gdbserver/Makefile.in
+++ b/gdb-7.1.x/gdb/gdbserver/Makefile.in
@@ -176,13 +176,13 @@ clean-info:
 
 gdbserver$(EXEEXT): $(OBS) ${ADD_DEPS} ${CDEPS}
 	rm -f gdbserver$(EXEEXT)
-	${CC-LD} $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) -o gdbserver$(EXEEXT) $(OBS) \
-	  $(GDBSERVER_LIBS) $(XM_CLIBS)
+	${CC-LD} $(INTERNAL_CFLAGS) $(OBS) $(GDBSERVER_LIBS) $(XM_CLIBS) \
+          $(INTERNAL_LDFLAGS) -o gdbserver$(EXEEXT)
 
 gdbreplay$(EXEEXT): $(GDBREPLAY_OBS)
 	rm -f gdbreplay$(EXEEXT)
-	${CC-LD} $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) \
-	  $(XM_CLIBS)
+	${CC-LD} $(INTERNAL_CFLAGS) -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) \
+          $(XM_CLIBS) $(INTERNAL_LDFLAGS)
 
 # Put the proper machine-specific files first, so M-. on a machine
 # specific routine gets the one for the correct machine.
diff --git a/gdb-7.1.x/gdb/gdbserver/configure b/gdb-7.1.x/gdb/gdbserver/configure
index 47bd81a..399d08b 100755
--- a/gdb-7.1.x/gdb/gdbserver/configure
+++ b/gdb-7.1.x/gdb/gdbserver/configure
@@ -4291,7 +4291,7 @@ srv_libs=
 USE_THREAD_DB=
 
 if test "$srv_linux_thread_db" = "yes"; then
-  srv_libs="-ldl"
+  srv_libs="-lthread_db -lc"
   old_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS -rdynamic"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -4356,7 +4356,7 @@ if test "${with_libthread_db+set}" = set; then :
 
 $as_echo "#define USE_LIBTHREAD_DB_DIRECTLY 1" >>confdefs.h
 
-  srv_libs="$srv_libthread_db_path"
+  srv_libs="$srv_libthread_db_path -lc"
 
 fi
 
diff --git a/gdb-7.1.x/gdb/gdbserver/configure.ac b/gdb-7.1.x/gdb/gdbserver/configure.ac
index 638c228..a13117b 100644
--- a/gdb-7.1.x/gdb/gdbserver/configure.ac
+++ b/gdb-7.1.x/gdb/gdbserver/configure.ac
@@ -180,7 +180,7 @@ srv_libs=
 USE_THREAD_DB=
 
 if test "$srv_linux_thread_db" = "yes"; then
-  srv_libs="-ldl"
+  srv_libs="-lthread_db -lc"
   old_LDFLAGS="$LDFLAGS"
   LDFLAGS="$LDFLAGS -rdynamic"
   AC_TRY_LINK([], [], [RDYNAMIC=-rdynamic], [RDYNAMIC=])
@@ -202,7 +202,7 @@ AC_ARG_WITH(libthread-db,
 AS_HELP_STRING([--with-libthread-db=PATH], [use given libthread_db directly]),
 [srv_libthread_db_path="${withval}"
   AC_DEFINE(USE_LIBTHREAD_DB_DIRECTLY, 1, [Define if we should use libthread_db directly.])
-  srv_libs="$srv_libthread_db_path"
+  srv_libs="$srv_libthread_db_path -lc"
 ])
 
 if test "$srv_xmlfiles" != ""; then
-- 
1.7.3.1