[PATCH 3/3] Find and link with -lmachuser -lhurduser

Yao Qi
2014-02-07T08:01:42Z

I see this link error when build native gdb for hurd.

/home/yao/Software/hurd-toolchain/bin/../lib/gcc/i686-pc-gnu/4.8.0/../../../../i686-pc-gnu/bin/ld: gnu-nat.o: undefined reference to symbol 'mach_port_destroy'
/home/yao/Software/hurd-toolchain/bin/../lib/gcc/i686-pc-gnu/4.8.0/../../../../i686-pc-gnu/bin/ld: note: 'mach_port_destroy' is defined in DSO
/home/yao/Software/hurd-toolchain/bin/../i686-pc-gnu/libc/lib/libmachuser.so.1 so try adding it to the linker command line
/home/yao/Software/hurd-toolchain/bin/../i686-pc-gnu/libc/lib/libmachuser.so.1:
could not read symbols: Invalid operation

This patch is to find and link GDB with -lmachuser and -lhurduser.

I find my patch is quite similar to another patch posted here
https://lists.debian.org/debian-hurd/2011/03/msg00198.html
in which, it mentioned that this change "will not be needed in next
version of libc0.3". However, I don't know much about hurd, and post
the patch for review, because it fixes the build failure after all.

gdb:

2014-02-07 Yao Qi <yao@codesourcery.com>

* configure.ac: Invoke AC_SEARCH_LIBS to search libmachuser and
libhurduser.
* configure: Regenerated.
---
gdb/configure | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/configure.ac | 4 ++
2 files changed, 118 insertions(+), 0 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index 8ae2e09..c4340b7 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -6711,6 +6711,120 @@ if test "$ac_res" != no; then :
fi

+# On GNU/Hurd we may need libmachuser and libhurduser (used by gnu-nat.c).
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing mach_port_destroy" >&5
+$as_echo_n "checking for library containing mach_port_destroy... " >&6; }
+if test "${ac_cv_search_mach_port_destroy+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 mach_port_destroy ();
+int
+main ()
+{
+return mach_port_destroy ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' machuser; 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_mach_port_destroy=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if test "${ac_cv_search_mach_port_destroy+set}" = set; then :
+ break
+fi
+done
+if test "${ac_cv_search_mach_port_destroy+set}" = set; then :
+
+else
+ ac_cv_search_mach_port_destroy=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_mach_port_destroy" >&5
+$as_echo "$ac_cv_search_mach_port_destroy" >&6; }
+ac_res=$ac_cv_search_mach_port_destroy
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing proc_getmsgport" >&5
+$as_echo_n "checking for library containing proc_getmsgport... " >&6; }
+if test "${ac_cv_search_proc_getmsgport+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 proc_getmsgport ();
+int
+main ()
+{
+return proc_getmsgport ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' hurduser; 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_proc_getmsgport=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if test "${ac_cv_search_proc_getmsgport+set}" = set; then :
+ break
+fi
+done
+if test "${ac_cv_search_proc_getmsgport+set}" = set; then :
+
+else
+ ac_cv_search_proc_getmsgport=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_proc_getmsgport" >&5
+$as_echo "$ac_cv_search_proc_getmsgport" >&6; }
+ac_res=$ac_cv_search_proc_getmsgport
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+

diff --git a/gdb/configure.ac b/gdb/configure.ac
index feb28f3..52aebf5 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -521,6 +521,10 @@ AM_ZLIB
# On HP/UX we may need libxpdl for dlgetmodinfo (used by solib-pa64.c).
AC_SEARCH_LIBS(dlgetmodinfo, [dl xpdl])

+# On GNU/Hurd we may need libmachuser and libhurduser (used by gnu-nat.c).
+AC_SEARCH_LIBS(mach_port_destroy, machuser)
+AC_SEARCH_LIBS(proc_getmsgport, hurduser)
+
AM_ICONV

# GDB may fork/exec the iconv program to get the list of supported character
--
1.7.7.6