From 13f33eb9ee5367715e648871d18e0d9b14ace815 Mon Sep 17 00:00:00 2001
From: David 'Digit' Turner <digit@android.com>
Date: Fri, 20 Apr 2012 15:51:23 +0200
Subject: ndk: Proper libthread_db support in gdbserver

Change-Id: If1c5f967e0f57d205215f28945e682bb5c291170
---
 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 aaad2e2549d349be0b2b61008b6c248c1cc2aab5..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
diff --git a/gdb-7.3.x/gdb/gdbserver/Makefile.in b/gdb-7.3.x/gdb/gdbserver/Makefile.in
index 7d565af..e5e8ae4 100644
--- a/gdb-7.3.x/gdb/gdbserver/Makefile.in
+++ b/gdb-7.3.x/gdb/gdbserver/Makefile.in
@@ -233,13 +233,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)
 
 IPA_OBJS=tracepoint-ipa.o utils-ipa.o regcache-ipa.o remote-utils-ipa.o ${IPA_DEPFILES}
 
diff --git a/gdb-7.3.x/gdb/gdbserver/configure b/gdb-7.3.x/gdb/gdbserver/configure
index 110e406..c50e9ac 100755
--- a/gdb-7.3.x/gdb/gdbserver/configure
+++ b/gdb-7.3.x/gdb/gdbserver/configure
@@ -4807,7 +4807,7 @@ rm -f core conftest.err conftest.$ac_objext \
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $found" >&5
 $as_echo "$found" >&6; }
   else
-    srv_libs="-lthread_db"
+    srv_libs="-lthread_db -lc"
   fi
 
   srv_thread_depfiles="thread-db.o proc-service.o"
@@ -4848,7 +4848,7 @@ fi
 # Check whether --with-libthread-db was given.
 if test "${with_libthread_db+set}" = set; then :
   withval=$with_libthread_db; srv_libthread_db_path="${withval}"
-  srv_libs="$srv_libthread_db_path"
+  srv_libs="$srv_libthread_db_path -lc"
 
 fi
 
diff --git a/gdb-7.3.x/gdb/gdbserver/configure.ac b/gdb-7.3.x/gdb/gdbserver/configure.ac
index 77e06c3..c70f3cf 100644
--- a/gdb-7.3.x/gdb/gdbserver/configure.ac
+++ b/gdb-7.3.x/gdb/gdbserver/configure.ac
@@ -315,7 +315,7 @@ if test "$srv_linux_thread_db" = "yes"; then
     LDFLAGS="$old_LDFLAGS"
     AC_MSG_RESULT($found)
   else
-    srv_libs="-lthread_db"
+    srv_libs="-lthread_db -lc"
   fi
 
   srv_thread_depfiles="thread-db.o proc-service.o"
@@ -332,7 +332,7 @@ fi
 AC_ARG_WITH(libthread-db,
 AS_HELP_STRING([--with-libthread-db=PATH], [use given libthread_db directly]),
 [srv_libthread_db_path="${withval}"
-  srv_libs="$srv_libthread_db_path"
+  srv_libs="$srv_libthread_db_path -lc"
 ])
 
 if test "$srv_libs" != "" -a "$srv_libs" != "-ldl"; then
-- 
1.7.6.rc0