From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 7CDFD3858C60; Thu, 14 Mar 2024 17:42:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CDFD3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1710438123; bh=UlQ2Io40p3BXq14/B7nqn0C5ykCoERT8getzJuQ7ZJ8=; h=From:To:Subject:Date:From; b=X4WGOjHLdzC+ERVV/fV7wELt5F9K7aLuA0VinzL/rHNRsVhpVvz9bjnTD507QRoaD RsrVa5sLjb8MuBBAi7uRfthjLm6zkEq+ncbJPssrlUyIbUpW6acULKBUVhLYZ4C903 S2gpLt80ipRVMzPRuVQjP7u1dksgqlocSfvdFews= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbserver/linux: probe for libiconv in configure X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 91e15dbaf9d05747fab0d33e5af7ae69c983398a X-Git-Newrev: da48217f315084097ef25226c0acab3bbd55ebd3 Message-Id: <20240314174203.7CDFD3858C60@sourceware.org> Date: Thu, 14 Mar 2024 17:42:03 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dda48217f3150= 84097ef25226c0acab3bbd55ebd3 commit da48217f315084097ef25226c0acab3bbd55ebd3 Author: Simon Marchi Date: Thu Mar 14 13:39:18 2024 -0400 gdbserver/linux: probe for libiconv in configure =20 Make gdbserver's build system locate libiconv when building for Linux. =20 Commit 07b3255c3bae ("Filter invalid encodings from Linux thread names") make libiconv madantory for building gdbserver on Linux. =20 While trying to cross-compile gdb for xtensa-fsf-linux-uclibc (with a toolchain generated with crosstool-ng), I got: =20 /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:48:10: fatal = error: iconv.h: No such file or directory 48 | #include | ^~~~~~~~~ =20 I downloaded GNU libiconv, built it for that host, and installed it in an arbitrary directory. I had to modify the gdbserver build system to locate libiconv and use it, the result is this patch. =20 I eventually found that crosstool-ng has a config option to make uclibc provide an implementation of iconv, which is of course much easier. But given that this patch is now written, I think it would be worth merging it, it could help some people who do not have iconv built-in their libc in the future (and may not have the luxury of rebuilding their libc like I do). =20 Using AM_ICONV in configure.ac adds these options for configure (the same we have for gdb): =20 --with-libiconv-prefix[=3DDIR] search for libiconv in DIR/include = and DIR/lib --without-libiconv-prefix don't search for libiconv in included= ir and libdir --with-libiconv-type=3DTYPE type of library to search for (auto= /static/shared) =20 It sets the `LIBICONV` variable with whatever is needed to link with libiconv, and adds the necessary `-I` flag to `CPPFLAGS`. =20 To avoid unnecessarily linking against libiconv on hosts that don't need it, set `MAYBE_LIBICONV` with the contents of `LIBICONV` only if the host is Linux, and use `MAYBE_LIBICONV` in `Makefile.in`. =20 Since libiconv is a hard requirement for Linux hosts, error out if it is not found. =20 The bits in acinclude.m4 are similar to what we have in gdb/acinclude.m4. =20 Update the top-level build system to support building against an in-tree libiconv (I did not test this part though). Something tells me that the all-gdbserver dependency on all-libiconv is unnecessary, since there is already a dependency of configure-gdbserver on all-libiconv (and all-gdbserver surely depends on configure-gdbserver). I just copied what's done for GDB though. =20 ChangeLog: =20 * Makefile.def: Add configure-gdbserver and all-gdbserver dependencies on all-libiconv. * Makefile.in: Re-generate. =20 Change-Id: I90f8ef88dd4917df5a68b45550d93622fc9cfed4 Approved-By: Tom Tromey Diff: --- ChangeLog | 6 + Makefile.def | 2 + Makefile.in | 2 + gdbserver/Makefile.in | 4 +- gdbserver/acinclude.m4 | 7 + gdbserver/aclocal.m4 | 4 - gdbserver/config.in | 3 + gdbserver/configure | 352 +++++++++++++++++++++++++++++++++++++++++++++= ++++ gdbserver/configure.ac | 16 +++ 9 files changed, 391 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b81f759ccd3..91b9f774ada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-03-14 Simon Marchi + + * Makefile.def: Add configure-gdbserver and all-gdbserver + dependencies on all-libiconv. + * Makefile.in: Re-generate. + 2024-01-15 Nick Clifton =20 * 2.42 branch point. diff --git a/Makefile.def b/Makefile.def index 3e00a729a0c..6b143ab10c6 100644 --- a/Makefile.def +++ b/Makefile.def @@ -461,9 +461,11 @@ dependencies =3D { module=3Dall-gdb; on=3Dall-libbackt= race; }; =20 // Host modules specific to gdbserver. dependencies =3D { module=3Dconfigure-gdbserver; on=3Dall-gnulib; }; +dependencies =3D { module=3Dconfigure-gdbserver; on=3Dall-libiconv; }; dependencies =3D { module=3Dall-gdbserver; on=3Dall-gdbsupport; }; dependencies =3D { module=3Dall-gdbserver; on=3Dall-gnulib; }; dependencies =3D { module=3Dall-gdbserver; on=3Dall-libiberty; }; +dependencies =3D { module=3Dall-gdbserver; on=3Dall-libiconv; }; =20 dependencies =3D { module=3Dconfigure-libgui; on=3Dconfigure-tcl; }; dependencies =3D { module=3Dconfigure-libgui; on=3Dconfigure-tk; }; diff --git a/Makefile.in b/Makefile.in index a1f64a2ab5a..589588dc23b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -67904,7 +67904,9 @@ all-gdb: maybe-all-opcodes all-gdb: maybe-all-libdecnumber all-gdb: maybe-all-libctf all-gdb: maybe-all-libbacktrace +configure-gdbserver: maybe-all-libiconv all-gdbserver: maybe-all-libiberty +all-gdbserver: maybe-all-libiconv configure-gdbsupport: maybe-configure-gettext all-gdbsupport: maybe-all-gettext configure-gprof: maybe-configure-gettext diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in index d12f8746611..c7120895a26 100644 --- a/gdbserver/Makefile.in +++ b/gdbserver/Makefile.in @@ -152,6 +152,8 @@ PTHREAD_LIBS =3D @PTHREAD_LIBS@ =20 WIN32APILIBS =3D @WIN32APILIBS@ =20 +MAYBE_LIBICONV =3D @MAYBE_LIBICONV@ + # INTERNAL_CFLAGS is the aggregate of all other *CFLAGS macros. INTERNAL_CFLAGS_BASE =3D ${GLOBAL_CFLAGS} \ ${PROFILE_CFLAGS} ${INCLUDE_CFLAGS} ${CPPFLAGS} $(PTHREAD_CFLAGS) @@ -354,7 +356,7 @@ gdbserver$(EXEEXT): $(sort $(OBS)) ${CDEPS} $(LIBGNU) $= (LIBIBERTY) \ $(CXXFLAGS) \ -o gdbserver$(EXEEXT) $(OBS) $(GDBSUPPORT) $(LIBGNU) \ $(LIBGNU_EXTRA_LIBS) $(LIBIBERTY) $(INTL) \ - $(GDBSERVER_LIBS) $(XM_CLIBS) $(WIN32APILIBS) + $(GDBSERVER_LIBS) $(XM_CLIBS) $(WIN32APILIBS) $(MAYBE_LIBICONV) =20 gdbreplay$(EXEEXT): $(sort $(GDBREPLAY_OBS)) $(LIBGNU) $(LIBIBERTY) \ $(INTL_DEPS) $(GDBSUPPORT) diff --git a/gdbserver/acinclude.m4 b/gdbserver/acinclude.m4 index db69b7d243b..5a00c6e9878 100644 --- a/gdbserver/acinclude.m4 +++ b/gdbserver/acinclude.m4 @@ -18,6 +18,13 @@ dnl anything else in gdbserver. m4_include(../config/codeset.m4) m4_include(../gdbsupport/common.m4) =20 +dnl For AM_ICONV. We need to explicitly include these other files before +dnl iconv.m4 to avoid warnings. +m4_include([../config/lib-ld.m4]) +m4_include([../config/lib-prefix.m4]) +m4_include([../config/lib-link.m4]) +m4_include([../config/iconv.m4]) + dnl For libiberty_INIT. m4_include(../gdbsupport/libiberty.m4) =20 diff --git a/gdbserver/aclocal.m4 b/gdbserver/aclocal.m4 index db9266266be..fe94a5bffc0 100644 --- a/gdbserver/aclocal.m4 +++ b/gdbserver/aclocal.m4 @@ -204,12 +204,8 @@ m4_include([../config/ax_pthread.m4]) m4_include([../config/depstand.m4]) m4_include([../config/gettext-sister.m4]) m4_include([../config/gettext.m4]) -m4_include([../config/iconv.m4]) m4_include([../config/intlmacosx.m4]) m4_include([../config/lead-dot.m4]) -m4_include([../config/lib-ld.m4]) -m4_include([../config/lib-link.m4]) -m4_include([../config/lib-prefix.m4]) m4_include([../config/nls.m4]) m4_include([../config/override.m4]) m4_include([../config/po.m4]) diff --git a/gdbserver/config.in b/gdbserver/config.in index ca4b9f4d6f2..47e1e722fe0 100644 --- a/gdbserver/config.in +++ b/gdbserver/config.in @@ -402,6 +402,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WS2TCPIP_H =20 +/* Define as const if the declaration of iconv() needs const. */ +#undef ICONV_CONST + /* Define to the address where bug reports for this package should be sent= . */ #undef PACKAGE_BUGREPORT =20 diff --git a/gdbserver/configure b/gdbserver/configure index 0942ef173d4..b85db9cd49d 100755 --- a/gdbserver/configure +++ b/gdbserver/configure @@ -623,6 +623,7 @@ ac_header_list=3D gt_needs=3D ac_subst_vars=3D'LTLIBOBJS LIBOBJS +MAYBE_LIBICONV GNULIB_STDINT_H extra_libraries IPA_DEPFILES @@ -14736,6 +14737,357 @@ if test x"$STDINT_H" !=3D x; then fi =20 =20 +# Check for libiconv. It is a requirement for Linux hosts, and others hos= ts +# don't use it at all. Define MAYBE_LIBICONV only if the host is Linux. + + + + + + am_save_CPPFLAGS=3D"$CPPFLAGS" + + for element in $INCICONV; do + haveit=3D + for x in $CPPFLAGS; do + + acl_save_prefix=3D"$prefix" + prefix=3D"$acl_final_prefix" + acl_save_exec_prefix=3D"$exec_prefix" + exec_prefix=3D"$acl_final_exec_prefix" + eval x=3D\"$x\" + exec_prefix=3D"$acl_save_exec_prefix" + prefix=3D"$acl_save_prefix" + + if test "X$x" =3D "X$element"; then + haveit=3Dyes + break + fi + done + if test -z "$haveit"; then + CPPFLAGS=3D"${CPPFLAGS}${CPPFLAGS:+ }$element" + fi + done + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 +$as_echo_n "checking for iconv... " >&6; } +if ${am_cv_func_iconv+:} false; then : + $as_echo_n "(cached) " >&6 +else + + am_cv_func_iconv=3D"no, consider installing GNU libiconv" + am_cv_lib_iconv=3Dno + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +iconv_t cd =3D iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + am_cv_func_iconv=3Dyes +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test "$am_cv_func_iconv" !=3D yes; then + am_save_LIBS=3D"$LIBS" + LIBS=3D"$LIBS $LIBICONV" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +iconv_t cd =3D iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + am_cv_lib_iconv=3Dyes + am_cv_func_iconv=3Dyes +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LIBS=3D"$am_save_LIBS" + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 +$as_echo "$am_cv_func_iconv" >&6; } + if test "$am_cv_func_iconv" =3D yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working iconv" >= &5 +$as_echo_n "checking for working iconv... " >&6; } +if ${am_cv_func_iconv_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + + am_save_LIBS=3D"$LIBS" + if test $am_cv_lib_iconv =3D yes; then + LIBS=3D"$LIBS $LIBICONV" + fi + am_cv_func_iconv_works=3Dno + for ac_iconv_const in '' 'const'; do + if test "$cross_compiling" =3D yes; then : + case "$host_os" in + aix* | hpux*) am_cv_func_iconv_works=3D"guessing no" ;; + *) am_cv_func_iconv_works=3D"guessing yes" ;; + esac +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +#ifndef ICONV_CONST +# define ICONV_CONST $ac_iconv_const +#endif + +int +main () +{ +int result =3D 0; + /* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from + successful returns. This is even documented in + */ + { + iconv_t cd_utf8_to_88591 =3D iconv_open ("ISO8859-1", "UTF-8"); + if (cd_utf8_to_88591 !=3D (iconv_t)(-1)) + { + static ICONV_CONST char input[] =3D "\342\202\254"; /* EURO SIGN */ + char buf[10]; + ICONV_CONST char *inptr =3D input; + size_t inbytesleft =3D strlen (input); + char *outptr =3D buf; + size_t outbytesleft =3D sizeof (buf); + size_t res =3D iconv (cd_utf8_to_88591, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res =3D=3D 0) + result |=3D 1; + iconv_close (cd_utf8_to_88591); + } + } + /* Test against Solaris 10 bug: Failures are not distinguishable from + successful returns. */ + { + iconv_t cd_ascii_to_88591 =3D iconv_open ("ISO8859-1", "646"); + if (cd_ascii_to_88591 !=3D (iconv_t)(-1)) + { + static ICONV_CONST char input[] =3D "\263"; + char buf[10]; + ICONV_CONST char *inptr =3D input; + size_t inbytesleft =3D strlen (input); + char *outptr =3D buf; + size_t outbytesleft =3D sizeof (buf); + size_t res =3D iconv (cd_ascii_to_88591, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res =3D=3D 0) + result |=3D 2; + iconv_close (cd_ascii_to_88591); + } + } + /* Test against AIX 6.1..7.1 bug: Buffer overrun. */ + { + iconv_t cd_88591_to_utf8 =3D iconv_open ("UTF-8", "ISO-8859-1"); + if (cd_88591_to_utf8 !=3D (iconv_t)(-1)) + { + static ICONV_CONST char input[] =3D "\304"; + static char buf[2] =3D { (char)0xDE, (char)0xAD }; + ICONV_CONST char *inptr =3D input; + size_t inbytesleft =3D 1; + char *outptr =3D buf; + size_t outbytesleft =3D 1; + size_t res =3D iconv (cd_88591_to_utf8, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res !=3D (size_t)(-1) || outptr - buf > 1 || buf[1] !=3D (char= )0xAD) + result |=3D 4; + iconv_close (cd_88591_to_utf8); + } + } +#if 0 /* This bug could be worked around by the caller. */ + /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ + { + iconv_t cd_88591_to_utf8 =3D iconv_open ("utf8", "iso88591"); + if (cd_88591_to_utf8 !=3D (iconv_t)(-1)) + { + static ICONV_CONST char input[] =3D "\304rger mit b\366sen B\374bc= hen ohne Augenma\337"; + char buf[50]; + ICONV_CONST char *inptr =3D input; + size_t inbytesleft =3D strlen (input); + char *outptr =3D buf; + size_t outbytesleft =3D sizeof (buf); + size_t res =3D iconv (cd_88591_to_utf8, + &inptr, &inbytesleft, + &outptr, &outbytesleft); + if ((int)res > 0) + result |=3D 8; + iconv_close (cd_88591_to_utf8); + } + } +#endif + /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is + provided. */ + { + /* Try standardized names. */ + iconv_t cd1 =3D iconv_open ("UTF-8", "EUC-JP"); + /* Try IRIX, OSF/1 names. */ + iconv_t cd2 =3D iconv_open ("UTF-8", "eucJP"); + /* Try AIX names. */ + iconv_t cd3 =3D iconv_open ("UTF-8", "IBM-eucJP"); + /* Try HP-UX names. */ + iconv_t cd4 =3D iconv_open ("utf8", "eucJP"); + if (cd1 =3D=3D (iconv_t)(-1) && cd2 =3D=3D (iconv_t)(-1) + && cd3 =3D=3D (iconv_t)(-1) && cd4 =3D=3D (iconv_t)(-1)) + result |=3D 16; + if (cd1 !=3D (iconv_t)(-1)) + iconv_close (cd1); + if (cd2 !=3D (iconv_t)(-1)) + iconv_close (cd2); + if (cd3 !=3D (iconv_t)(-1)) + iconv_close (cd3); + if (cd4 !=3D (iconv_t)(-1)) + iconv_close (cd4); + } + return result; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + am_cv_func_iconv_works=3Dyes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + test "$am_cv_func_iconv_works" =3D no || break + done + LIBS=3D"$am_save_LIBS" + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" = >&5 +$as_echo "$am_cv_func_iconv_works" >&6; } + case "$am_cv_func_iconv_works" in + *no) am_func_iconv=3Dno am_cv_lib_iconv=3Dno ;; + *) am_func_iconv=3Dyes ;; + esac + else + am_func_iconv=3Dno am_cv_lib_iconv=3Dno + fi + if test "$am_func_iconv" =3D yes; then + +$as_echo "#define HAVE_ICONV 1" >>confdefs.h + + fi + if test "$am_cv_lib_iconv" =3D yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with lib= iconv" >&5 +$as_echo_n "checking how to link with libiconv... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 +$as_echo "$LIBICONV" >&6; } + else + CPPFLAGS=3D"$am_save_CPPFLAGS" + LIBICONV=3D + LTLIBICONV=3D + fi + + + + if test "$am_cv_func_iconv" =3D yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether iconv is com= patible with its POSIX signature" >&5 +$as_echo_n "checking whether iconv is compatible with its POSIX signature.= .. " >&6; } +if ${gl_cv_iconv_nonconst+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +extern +#ifdef __cplusplus +"C" +#endif +size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outb= uf, size_t *outbytesleft); + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + gl_cv_iconv_nonconst=3Dyes +else + gl_cv_iconv_nonconst=3Dno +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_iconv_nonconst" >&5 +$as_echo "$gl_cv_iconv_nonconst" >&6; } + else + gl_cv_iconv_nonconst=3Dyes + fi + if test $gl_cv_iconv_nonconst =3D yes; then + iconv_arg1=3D"" + else + iconv_arg1=3D"const" + fi + +cat >>confdefs.h <<_ACEOF +#define ICONV_CONST $iconv_arg1 +_ACEOF + + + + if test "$am_func_iconv" =3D yes; then + if test -n "$LIBICONV"; then + am_cv_func_iconv_summary=3D'yes, in libiconv' + else + am_cv_func_iconv_summary=3D'yes, in libc' + fi + else + if test "$am_cv_func_iconv" =3D yes; then + am_cv_func_iconv_summary=3D'not working, consider installing GNU lib= iconv' + else + am_cv_func_iconv_summary=3D'no, consider installing GNU libiconv' + fi + fi + +MAYBE_LIBICONV=3D +case "$host" in + *linux*) + if test "$am_cv_func_iconv" !=3D yes; then + as_fn_error $? "could not find libiconv (required for host $host)" "= $LINENO" 5 + fi + + MAYBE_LIBICONV=3D"$LIBICONV" + ;; +esac + + + ac_config_files=3D"$ac_config_files Makefile" =20 =20 diff --git a/gdbserver/configure.ac b/gdbserver/configure.ac index 280043dd7fc..ee0de9decbd 100644 --- a/gdbserver/configure.ac +++ b/gdbserver/configure.ac @@ -456,6 +456,22 @@ if test x"$STDINT_H" !=3D x; then fi AC_SUBST(GNULIB_STDINT_H) =20 +# Check for libiconv. It is a requirement for Linux hosts, and others hos= ts +# don't use it at all. Define MAYBE_LIBICONV only if the host is Linux. +AM_ICONV +MAYBE_LIBICONV=3D +case "$host" in + *linux*) + if test "$am_cv_func_iconv" !=3D yes; then + AC_MSG_ERROR([could not find libiconv (required for host $host)]) + fi + + MAYBE_LIBICONV=3D"$LIBICONV" + ;; +esac + +AC_SUBST(MAYBE_LIBICONV) + AC_CONFIG_FILES([Makefile]) =20 AC_OUTPUT