[PATCH 00/11] libctf: various portability fixes and small bugfixes

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/11] libctf: various portability fixes and small bugfixes

Nick Alcock
These deal with bug 25120 (a bunch of portability problems: elfcpp, used by
gold, contains the same problem so I fixed it there too), fix another bunch of
portability problems which appeared when binutils libctf hit the FreeBSD ports
tree, and fix a bunch of problems with forwards which emerged during the
development of the CTF-deduplicating linker and during ongoing testing of the
non-deduplicating linker.

It also finally gets --disable-libctf working (this bit is an older patch
that I simply never got around to pushing, and has been reviewed already:
it has a GDB portion which needed some changes and has been posted to
the GDB list already).

There's also one small feature addition: like objdump, readelf can now view .ctf
sections that contain CTF archives, and knows how the linker structures these
(with a .ctf member that is the parent of all the other members).  Since the
linker emits these whenever conflicting types with the same name are encountered
in a single program, without this capability there are lots of programs that
objdump --ctf can view but readelf --ctf=.ctf claims is a corrupted file.
This required a small API addition to libctf to open CTF archives from already-
read memory buffers while specifying string and symbol tables.

The libiberty and binutils bits outside the first patch in the series have not
appeared here before and need review.

Nick Alcock (11):
  binutils, ld: work with --disable-libctf
  libctf: create: non-root-visible types should not appear in name
    tables
  libctf: create: don't add forwards if the type added already exists
  libctf: create: ctf_add_type should hand back already-added non-SoUs
  libctf: create: forwards are always in the namespace of their referent
  libctf, binutils: support CTF archives like objdump
  libiberty, include, libctf: Use bsearch_r to avoid nonportable
    __thread
  libctf: work with compilers not supporting GNU C attributes
  libctf, elfcpp, gold: do not assume that <byteswap.h> contains bswap_*
  libctf: add some missing #includes.
  libctf: support platforms with separate libintl

 binutils/ChangeLog       |  35 ++++++++
 binutils/Makefile.am     |   5 ++
 binutils/Makefile.in     |   9 ++-
 binutils/aclocal.m4      |   1 +
 binutils/config.in       |   3 +
 binutils/configure       |  39 ++++++++-
 binutils/configure.ac    |   6 ++
 binutils/doc/Makefile.in |   1 +
 binutils/objdump.c       |  27 ++++++-
 binutils/readelf.c       | 118 +++++++++++++++++++--------
 elfcpp/ChangeLog         |  10 +++
 elfcpp/elfcpp_swap.h     |  16 ++--
 gold/ChangeLog           |   7 ++
 gold/config.in           |  12 +++
 gold/configure           | 127 ++++++++++++++++++-----------
 gold/configure.ac        |   3 +
 include/ChangeLog        |   9 +++
 include/ctf-api.h        |   4 +
 include/libiberty.h      |   7 ++
 ld/ChangeLog             |  30 +++++++
 ld/Makefile.am           |   4 +
 ld/Makefile.in           |   5 +-
 ld/aclocal.m4            |   1 +
 ld/config.in             |   3 +
 ld/configure             |  42 +++++++++-
 ld/configure.ac          |   9 +++
 ld/ldelfgen.c            |  14 ++++
 ld/ldlang.c              |  35 ++++++++
 libctf/ChangeLog         |  52 ++++++++++++
 libctf/Makefile.in       |  19 ++++-
 libctf/aclocal.m4        |   3 +-
 libctf/config.h.in       |  16 ++++
 libctf/configure         | 167 ++++++++++++++++++++++++++++++++++++++-
 libctf/configure.ac      |   4 +
 libctf/ctf-archive.c     |  93 ++++++++++++++++------
 libctf/ctf-create.c      |  49 ++++++++----
 libctf/ctf-impl.h        |  15 +++-
 libctf/ctf-open-bfd.c    |  69 ++--------------
 libctf/ctf-open.c        |  37 +++++++--
 libctf/libctf.ver        |   1 +
 libctf/swap.h            |  16 ++--
 libiberty/ChangeLog      |   8 ++
 libiberty/Makefile.in    |  12 ++-
 libiberty/bsearch_r.c    |  92 +++++++++++++++++++++
 44 files changed, 1016 insertions(+), 219 deletions(-)
 create mode 100644 libiberty/bsearch_r.c

--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 01/11] binutils, ld: work with --disable-libctf

Nick Alcock
This unfortunately means conditionalizing out all the libctf code, but
the result is not too unbearably ugly, if a bit repetitive.  I have
stubbed out code in the !ENABLE_LIBCTF path to avoid extra redundant
ifdefs where it seems that might be helpful.  (The stubs are not too
disruptive, but I've tried to keep them on one line where possible to
avoid filling up the screen with stubs that nobody would care about.
If this is too much of a coding style violation I can change it.)

Changes since v2: use GCC_ENABLE rather than repeating all the
                  AC_ARG_ENABLE stuff over and over again.

ld/
        * configure.ac [--enable-libctf]: New, default yes.
        Set ENABLE_LIBCTF accordingly.
        * Makefile.am [!ENABLE_LIBCTF]: Empty LIBCTF.
        * configure: Regenerate.
        * config.in: Regenerate.
        * Makefile.in: Regenerate.
        * aclocal.m4: Regenerate.
        * ldlang.c (ctf_output): Conditionalize on ENABLE_LIBCTF.
        (ldlang_open_ctf): Likewise.
        (lang_merge_ctf): Likewise.
        (ldlang_ctf_apply_strsym): Likewise.
        (lang_write_ctf): Likewise.
        (ldlang_write_ctf_late): Likewise.
        (ldlang_open_ctf) [!ENABLE_LIBCTF]: Warn about the presence of CTF
        sections.
        (lang_merge_ctf) [!ENABLE_LIBCTF]: New stub.
        (ldlang_ctf_apply_strsym) [!ENABLE_LIBCTF]: Likewise.
        (lang_write_ctf) [!ENABLE_LIBCTF]: Likewise.
        (ldlang_write_ctf_late) [!ENABLE_LIBCTF]: Likewise.
        * ldelfgen.c (ldelf_emit_ctf_early): Conditionalize on
        ENABLE_LIBCTF.
        (struct ctf_strsym_iter_cb_arg): Likewise.
        (ldelf_ctf_strtab_iter_cb): Likewise.
        (ldelf_ctf_symbols_iter_cb): Likewise.
        (ldelf_examine_strtab_for_ctf): Likewise.
        (ldelf_emit_ctf_early) [!ENABLE_LIBCTF]: New stub.
        (ldelf_examine_strtab_for_ctf) [!ENABLE_LIBCTF]: New stub.

binutils/
        * configure.ac [--enable-libctf]: New, default yes.
        Set ENABLE_LIBCTF accordingly.
        * Makefile.am [!ENABLE_LIBCTF]: Empty LIBCTF and LIBCTF_NOBFD.
        * configure: Regenerate.
        * config.in: Regenerate.
        * Makefile.in: Regenerate.
        * aclocal.m4: Regenerate.
        * objdump.c (usage): Conditionalize portions on ENABLE_LIBCTF.
        (option_values): Likewise.
        (long_options): Likewise.
        (main): Likewise.
        (dump_ctf_indent_lines): Conditionalize out when !ENABLE_LIBCTF.
        (make_ctfsect): Likewise.
        (dump_ctf_archive_member): Likewise.
        (dump_ctf) [ENABLE_LIBCTF]: Likewise.
        (dump_ctf) [!ENABLE_LIBCTF]: New empty stub.
        * readelf.c (options): Conditionalize portions on ENABLE_LIBCTF.
        (usage): Likewise.
        (process_section_contents): Likewise.
        (shdr_to_ctf_sect): Conditionalize out when !ENABLE_LIBCTF.
        (dump_ctf_indent_lines): Likewise.
        (dump_section_as_ctf) [ENABLE_LIBCTF]: Likewise.
---
 binutils/ChangeLog       | 25 ++++++++++++++++++++++++
 binutils/Makefile.am     |  5 +++++
 binutils/Makefile.in     |  9 +++++++--
 binutils/aclocal.m4      |  1 +
 binutils/config.in       |  3 +++
 binutils/configure       | 39 +++++++++++++++++++++++++++++++++++--
 binutils/configure.ac    |  6 ++++++
 binutils/doc/Makefile.in |  1 +
 binutils/objdump.c       | 27 +++++++++++++++++++++++---
 binutils/readelf.c       |  8 ++++++++
 ld/ChangeLog             | 30 ++++++++++++++++++++++++++++
 ld/Makefile.am           |  4 ++++
 ld/Makefile.in           |  5 ++++-
 ld/aclocal.m4            |  1 +
 ld/config.in             |  3 +++
 ld/configure             | 42 ++++++++++++++++++++++++++++++++++++++--
 ld/configure.ac          |  9 +++++++++
 ld/ldelfgen.c            | 14 ++++++++++++++
 ld/ldlang.c              | 35 +++++++++++++++++++++++++++++++++
 19 files changed, 257 insertions(+), 10 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 80c7fc32dd..4490679ca8 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,28 @@
+2019-09-30  Nick Alcock  <[hidden email]>
+
+ * configure.ac [--enable-libctf]: New, default yes.
+ Set ENABLE_LIBCTF accordingly.
+ * Makefile.am [!ENABLE_LIBCTF]: Empty LIBCTF and LIBCTF_NOBFD.
+ * configure: Regenerate.
+ * config.in: Regenerate.
+ * Makefile.in: Regenerate.
+ * aclocal.m4: Regenerate.
+ * objdump.c (usage): Conditionalize portions on ENABLE_LIBCTF.
+ (option_values): Likewise.
+ (long_options): Likewise.
+ (main): Likewise.
+ (dump_ctf_indent_lines): Conditionalize out when !ENABLE_LIBCTF.
+ (make_ctfsect): Likewise.
+ (dump_ctf_archive_member): Likewise.
+ (dump_ctf) [ENABLE_LIBCTF]: Likewise.
+ (dump_ctf) [!ENABLE_LIBCTF]: New empty stub.
+ * readelf.c (options): Conditionalize portions on ENABLE_LIBCTF.
+ (usage): Likewise.
+ (process_section_contents): Likewise.
+ (shdr_to_ctf_sect): Conditionalize out when !ENABLE_LIBCTF.
+ (dump_ctf_indent_lines): Likewise.
+ (dump_section_as_ctf) [ENABLE_LIBCTF]: Likewise.
+
 2019-12-11  Alan Modra  <[hidden email]>
 
  * od-xcoff.c (dump_dumpx_core): Adjust for bfd_h_get_8 change.
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index 4c90a0bef3..40e4e6d35d 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -162,8 +162,13 @@ BFDLIB = ../bfd/libbfd.la
 
 OPCODES = ../opcodes/libopcodes.la
 
+if ENABLE_LIBCTF
 LIBCTF = ../libctf/libctf.la
 LIBCTF_NOBFD = ../libctf/libctf-nobfd.la
+else
+LIBCTF =
+LIBCTF_NOBFD =
+endif
 
 LIBIBERTY = ../libiberty/libiberty.a
 
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index be96d2db0e..d8da0feda0 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -122,6 +122,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
  $(top_srcdir)/../bfd/warning.m4 $(top_srcdir)/../config/acx.m4 \
  $(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
  $(top_srcdir)/../config/gettext-sister.m4 \
  $(top_srcdir)/../config/iconv.m4 \
  $(top_srcdir)/../config/largefile.m4 \
@@ -220,6 +221,7 @@ objcopy_LDADD = $(LDADD)
 am_objdump_OBJECTS = objdump.$(OBJEXT) dwarf.$(OBJEXT) prdbg.$(OBJEXT) \
  $(am__objects_3) $(am__objects_1) $(am__objects_2)
 objdump_OBJECTS = $(am_objdump_OBJECTS)
+@ENABLE_LIBCTF_TRUE@am__DEPENDENCIES_2 = ../libctf/libctf.la
 am_ranlib_OBJECTS = ar.$(OBJEXT) is-ranlib.$(OBJEXT) arparse.$(OBJEXT) \
  arlex.$(OBJEXT) arsup.$(OBJEXT) rename.$(OBJEXT) \
  binemul.$(OBJEXT) emul_$(EMULATION).$(OBJEXT) $(am__objects_1)
@@ -227,6 +229,7 @@ ranlib_OBJECTS = $(am_ranlib_OBJECTS)
 am_readelf_OBJECTS = readelf.$(OBJEXT) version.$(OBJEXT) \
  unwind-ia64.$(OBJEXT) dwarf.$(OBJEXT) $(am__objects_2)
 readelf_OBJECTS = $(am_readelf_OBJECTS)
+@ENABLE_LIBCTF_TRUE@am__DEPENDENCIES_3 = ../libctf/libctf-nobfd.la
 am_size_OBJECTS = size.$(OBJEXT) $(am__objects_1)
 size_OBJECTS = $(am_size_OBJECTS)
 size_LDADD = $(LDADD)
@@ -655,8 +658,10 @@ BULIBS = bucomm.c version.c filemode.c
 ELFLIBS = elfcomm.c
 BFDLIB = ../bfd/libbfd.la
 OPCODES = ../opcodes/libopcodes.la
-LIBCTF = ../libctf/libctf.la
-LIBCTF_NOBFD = ../libctf/libctf-nobfd.la
+@ENABLE_LIBCTF_FALSE@LIBCTF =
+@ENABLE_LIBCTF_TRUE@LIBCTF = ../libctf/libctf.la
+@ENABLE_LIBCTF_FALSE@LIBCTF_NOBFD =
+@ENABLE_LIBCTF_TRUE@LIBCTF_NOBFD = ../libctf/libctf-nobfd.la
 LIBIBERTY = ../libiberty/libiberty.a
 POTFILES = $(CFILES) $(DEBUG_SRCS) $(HFILES)
 EXPECT = expect
diff --git a/binutils/aclocal.m4 b/binutils/aclocal.m4
index 4fa32fffd8..8bf2e9e242 100644
--- a/binutils/aclocal.m4
+++ b/binutils/aclocal.m4
@@ -1189,6 +1189,7 @@ m4_include([../bfd/acinclude.m4])
 m4_include([../bfd/warning.m4])
 m4_include([../config/acx.m4])
 m4_include([../config/depstand.m4])
+m4_include([../config/enable.m4])
 m4_include([../config/gettext-sister.m4])
 m4_include([../config/iconv.m4])
 m4_include([../config/largefile.m4])
diff --git a/binutils/config.in b/binutils/config.in
index 72ead4eb61..a3bb053bc6 100644
--- a/binutils/config.in
+++ b/binutils/config.in
@@ -21,6 +21,9 @@
 /* Should strings use -a behavior by default? */
 #undef DEFAULT_STRINGS_ALL
 
+/* Handle .ctf type-info sections */
+#undef ENABLE_LIBCTF
+
 /* Define to 1 if translation of program messages to the user's native
    language is requested. */
 #undef ENABLE_NLS
diff --git a/binutils/configure b/binutils/configure
index 50f8d5b1a2..dba33d312f 100755
--- a/binutils/configure
+++ b/binutils/configure
@@ -684,6 +684,8 @@ WARN_WRITE_STRINGS
 NO_WERROR
 WARN_CFLAGS_FOR_BUILD
 WARN_CFLAGS
+ENABLE_LIBCTF_FALSE
+ENABLE_LIBCTF_TRUE
 OTOOL64
 OTOOL
 LIPO
@@ -813,6 +815,7 @@ enable_largefile
 enable_targets
 enable_deterministic_archives
 enable_default_strings_all
+enable_libctf
 enable_werror
 enable_build_warnings
 enable_nls
@@ -1469,6 +1472,7 @@ Optional Features:
                           ar and ranlib default to -D behavior
   --disable-default-strings-all
                           strings defaults to --data behavior
+  --enable-libctf         Handle .ctf type-info sections [default=yes]
   --enable-werror         treat compile warnings as errors
   --enable-build-warnings enable build-time compiler warnings
   --disable-nls           do not use Native Language Support
@@ -11523,7 +11527,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11526 "configure"
+#line 11530 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11629,7 +11633,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11632 "configure"
+#line 11636 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12241,6 +12245,33 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+ # Check whether --enable-libctf was given.
+if test "${enable_libctf+set}" = set; then :
+  enableval=$enable_libctf;
+      case "$enableval" in
+       yes|no) ;;
+       *) as_fn_error $? "Argument to enable/disable libctf must be yes or no" "$LINENO" 5 ;;
+      esac
+
+else
+  enable_libctf=yes
+fi
+
+
+if test "${enable_libctf}" = yes; then
+
+$as_echo "#define ENABLE_LIBCTF 1" >>confdefs.h
+
+fi
+ if test "${enable_libctf}" = yes; then
+  ENABLE_LIBCTF_TRUE=
+  ENABLE_LIBCTF_FALSE='#'
+else
+  ENABLE_LIBCTF_TRUE='#'
+  ENABLE_LIBCTF_FALSE=
+fi
+
+
 
 # Set the 'development' global.
 . $srcdir/../bfd/development.sh
@@ -15308,6 +15339,10 @@ else
   am__EXEEXT_FALSE=
 fi
 
+if test -z "${ENABLE_LIBCTF_TRUE}" && test -z "${ENABLE_LIBCTF_FALSE}"; then
+  as_fn_error $? "conditional \"ENABLE_LIBCTF\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
   as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/binutils/configure.ac b/binutils/configure.ac
index b1cd4552f2..a043bc3be4 100644
--- a/binutils/configure.ac
+++ b/binutils/configure.ac
@@ -66,6 +66,12 @@ fi], [default_strings_all=1])
 AC_DEFINE_UNQUOTED(DEFAULT_STRINGS_ALL, $default_strings_all,
    [Should strings use -a behavior by default?])
 
+GCC_ENABLE([libctf], [yes], [], [Handle .ctf type-info sections])
+if test "${enable_libctf}" = yes; then
+    AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])
+fi
+AM_CONDITIONAL(ENABLE_LIBCTF, test "${enable_libctf}" = yes)
+
 AM_BINUTILS_WARNINGS
 
 AC_CONFIG_HEADERS(config.h:config.in)
diff --git a/binutils/doc/Makefile.in b/binutils/doc/Makefile.in
index 3023c7bdd3..361dff8ab1 100644
--- a/binutils/doc/Makefile.in
+++ b/binutils/doc/Makefile.in
@@ -111,6 +111,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
  $(top_srcdir)/../bfd/warning.m4 $(top_srcdir)/../config/acx.m4 \
  $(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
  $(top_srcdir)/../config/gettext-sister.m4 \
  $(top_srcdir)/../config/iconv.m4 \
  $(top_srcdir)/../config/largefile.m4 \
diff --git a/binutils/objdump.c b/binutils/objdump.c
index c10136edc3..bcf9d9d767 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -228,7 +228,13 @@ usage (FILE *stream, int status)
           =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
           =addr,=cu_index,=links,=follow-links]\n\
                            Display DWARF info in the file\n\
+"));
+#ifdef ENABLE_LIBCTF
+  fprintf (stream, _("\
   --ctf=SECTION            Display CTF info from SECTION\n\
+"));
+#endif
+  fprintf (stream, _("\
   -t, --syms               Display the contents of the symbol table(s)\n\
   -T, --dynamic-syms       Display the contents of the dynamic symbol table\n\
   -r, --reloc              Display the relocation entries in the file\n\
@@ -277,8 +283,11 @@ usage (FILE *stream, int status)
       --dwarf-start=N        Display DIEs starting with N, at the same depth\n\
                              or deeper\n\
       --dwarf-check          Make additional dwarf internal consistency checks.\
-      \n\
+      \n"));
+#ifdef ENABLE_LIBCTF
+      fprintf (stream, _("\
       --ctf-parent=SECTION     Use SECTION as the CTF parent\n\n"));
+#endif
       list_supported_targets (program_name, stream);
       list_supported_architectures (program_name, stream);
 
@@ -314,9 +323,11 @@ enum option_values
     OPTION_RECURSE_LIMIT,
     OPTION_NO_RECURSE_LIMIT,
     OPTION_INLINES,
-    OPTION_SOURCE_COMMENT,
-    OPTION_CTF,
+    OPTION_SOURCE_COMMENT
+#ifdef ENABLE_LIBCTF
+    ,OPTION_CTF,
     OPTION_CTF_PARENT
+#endif
   };
 
 static struct option long_options[]=
@@ -360,8 +371,10 @@ static struct option long_options[]=
   {"special-syms", no_argument, &dump_special_syms, 1},
   {"include", required_argument, NULL, 'I'},
   {"dwarf", optional_argument, NULL, OPTION_DWARF},
+#ifdef ENABLE_LIBCTF
   {"ctf", required_argument, NULL, OPTION_CTF},
   {"ctf-parent", required_argument, NULL, OPTION_CTF_PARENT},
+#endif
   {"stabs", no_argument, NULL, 'G'},
   {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
   {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
@@ -3216,6 +3229,7 @@ dump_bfd_header (bfd *abfd)
 }
 
 
+#ifdef ENABLE_LIBCTF
 /* Formatting callback function passed to ctf_dump.  Returns either the pointer
    it is passed, or a pointer to newly-allocated storage, in which case
    dump_ctf() will free it when it no longer needs it.  */
@@ -3357,6 +3371,11 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
   free (parentdata);
   free (ctfdata);
 }
+#else
+static void
+dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED,
+  const char *parent_name ATTRIBUTE_UNUSED) {}
+#endif
 
 
 static void
@@ -4519,6 +4538,7 @@ main (int argc, char **argv)
  case OPTION_DWARF_CHECK:
   dwarf_check = TRUE;
   break;
+#ifdef ENABLE_LIBCTF
  case OPTION_CTF:
   dump_ctf_section_info = TRUE;
   dump_ctf_section_name = xstrdup (optarg);
@@ -4527,6 +4547,7 @@ main (int argc, char **argv)
  case OPTION_CTF_PARENT:
   dump_ctf_parent_name = xstrdup (optarg);
   break;
+#endif
  case 'G':
   dump_stab_section_info = TRUE;
   seenflag = TRUE;
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 1d8f62bf50..e92c3ce1ed 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -4465,11 +4465,13 @@ static struct option options[] =
   {"dwarf-start",      required_argument, 0, OPTION_DWARF_START},
   {"dwarf-check",      no_argument, 0, OPTION_DWARF_CHECK},
 
+#ifdef ENABLE_LIBCTF
   {"ctf",       required_argument, 0, OPTION_CTF_DUMP},
 
   {"ctf-symbols",      required_argument, 0, OPTION_CTF_SYMBOLS},
   {"ctf-strings",      required_argument, 0, OPTION_CTF_STRINGS},
   {"ctf-parent",       required_argument, 0, OPTION_CTF_PARENT},
+#endif
 
   {"version",       no_argument, 0, 'v'},
   {"wide",       no_argument, 0, 'W'},
@@ -4520,6 +4522,7 @@ usage (FILE * stream)
   --dwarf-depth=N        Do not display DIEs at depth N or greater\n\
   --dwarf-start=N        Display DIEs starting with N, at the same depth\n\
                          or deeper\n"));
+#ifdef ENABLE_LIBCTF
   fprintf (stream, _("\
   --ctf=<number|name>    Display CTF info from section <number|name>\n\
   --ctf-parent=<number|name>\n\
@@ -4528,6 +4531,7 @@ usage (FILE * stream)
                          Use section <number|name> as the CTF external symtab\n\n\
   --ctf-strings=<number|name>\n\
                          Use section <number|name> as the CTF external strtab\n\n"));
+#endif
 
 #ifdef SUPPORT_DISASSEMBLY
   fprintf (stream, _("\
@@ -13901,6 +13905,7 @@ dump_section_as_bytes (Elf_Internal_Shdr *  section,
   return TRUE;
 }
 
+#ifdef ENABLE_LIBCTF
 static ctf_sect_t *
 shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
 {
@@ -14061,6 +14066,7 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   free (strdata);
   return ret;
 }
+#endif
 
 static bfd_boolean
 load_specific_debug_section (enum dwarf_section_display_enum  debug,
@@ -14400,11 +14406,13 @@ process_section_contents (Filedata * filedata)
     res = FALSE;
  }
 
+#ifdef ENABLE_LIBCTF
       if (dump & CTF_DUMP)
  {
   if (! dump_section_as_ctf (section, filedata))
     res = FALSE;
  }
+#endif
     }
 
   /* Check to see if the user requested a
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 4b7e746498..2a73b6fb6f 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,33 @@
+2019-09-30  Nick Alcock  <[hidden email]>
+
+ * configure.ac [--enable-libctf]: New, default yes.
+ Set ENABLE_LIBCTF accordingly.
+ * Makefile.am [!ENABLE_LIBCTF]: Empty LIBCTF.
+ * configure: Regenerate.
+ * config.in: Regenerate.
+ * Makefile.in: Regenerate.
+ * aclocal.m4: Regenerate.
+ * ldlang.c (ctf_output): Conditionalize on ENABLE_LIBCTF.
+ (ldlang_open_ctf): Likewise.
+ (lang_merge_ctf): Likewise.
+ (ldlang_ctf_apply_strsym): Likewise.
+ (lang_write_ctf): Likewise.
+ (ldlang_write_ctf_late): Likewise.
+ (ldlang_open_ctf) [!ENABLE_LIBCTF]: Warn about the presence of CTF
+ sections.
+ (lang_merge_ctf) [!ENABLE_LIBCTF]: New stub.
+ (ldlang_ctf_apply_strsym) [!ENABLE_LIBCTF]: Likewise.
+ (lang_write_ctf) [!ENABLE_LIBCTF]: Likewise.
+ (ldlang_write_ctf_late) [!ENABLE_LIBCTF]: Likewise.
+ * ldelfgen.c (ldelf_emit_ctf_early): Conditionalize on
+ ENABLE_LIBCTF.
+ (struct ctf_strsym_iter_cb_arg): Likewise.
+ (ldelf_ctf_strtab_iter_cb): Likewise.
+ (ldelf_ctf_symbols_iter_cb): Likewise.
+ (ldelf_examine_strtab_for_ctf): Likewise.
+ (ldelf_emit_ctf_early) [!ENABLE_LIBCTF]: New stub.
+ (ldelf_examine_strtab_for_ctf) [!ENABLE_LIBCTF]: New stub.
+
 2019-12-12  H.J. Lu  <[hidden email]>
 
  * testsuite/ld-i386/align-branch-1.d: New file.
diff --git a/ld/Makefile.am b/ld/Makefile.am
index ddc7a78368..c43bb76bb3 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -157,7 +157,11 @@ AM_CPPFLAGS = -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) @zlibinc@ \
 
 BFDLIB = ../bfd/libbfd.la
 LIBIBERTY = ../libiberty/libiberty.a
+if ENABLE_LIBCTF
 LIBCTF = ../libctf/libctf.la
+else
+LIBCTF =
+endif
 
 # These all start with e so 'make clean' can find them.
 ALL_EMULATION_SOURCES = \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index fdf06128b2..0a58b4a369 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -113,6 +113,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
  $(top_srcdir)/../bfd/warning.m4 $(top_srcdir)/../config/acx.m4 \
  $(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
  $(top_srcdir)/../config/gettext-sister.m4 \
  $(top_srcdir)/../config/largefile.m4 \
  $(top_srcdir)/../config/lcmessage.m4 \
@@ -189,6 +190,7 @@ am_ld_new_OBJECTS = ldgram.$(OBJEXT) ldlex-wrapper.$(OBJEXT) \
  $(am__objects_1) ldbuildid.$(OBJEXT)
 ld_new_OBJECTS = $(am_ld_new_OBJECTS)
 am__DEPENDENCIES_1 =
+@ENABLE_LIBCTF_TRUE@am__DEPENDENCIES_2 = ../libctf/libctf.la
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
 am__v_P_0 = false
@@ -647,7 +649,8 @@ AM_CPPFLAGS = -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) @zlibinc@ \
 
 BFDLIB = ../bfd/libbfd.la
 LIBIBERTY = ../libiberty/libiberty.a
-LIBCTF = ../libctf/libctf.la
+@ENABLE_LIBCTF_FALSE@LIBCTF =
+@ENABLE_LIBCTF_TRUE@LIBCTF = ../libctf/libctf.la
 
 # These all start with e so 'make clean' can find them.
 ALL_EMULATION_SOURCES = \
diff --git a/ld/aclocal.m4 b/ld/aclocal.m4
index 7df8bf68f1..f6e87a228a 100644
--- a/ld/aclocal.m4
+++ b/ld/aclocal.m4
@@ -1189,6 +1189,7 @@ m4_include([../bfd/acinclude.m4])
 m4_include([../bfd/warning.m4])
 m4_include([../config/acx.m4])
 m4_include([../config/depstand.m4])
+m4_include([../config/enable.m4])
 m4_include([../config/gettext-sister.m4])
 m4_include([../config/largefile.m4])
 m4_include([../config/lcmessage.m4])
diff --git a/ld/config.in b/ld/config.in
index d93c9b0830..c302b2e250 100644
--- a/ld/config.in
+++ b/ld/config.in
@@ -27,6 +27,9 @@
    */
 #undef DEFAULT_NEW_DTAGS
 
+/* Handle .ctf type-info sections */
+#undef ENABLE_LIBCTF
+
 /* Define to 1 if translation of program messages to the user's native
    language is requested. */
 #undef ENABLE_NLS
diff --git a/ld/configure b/ld/configure
index 2e5e10dbf3..a262d0a0f0 100755
--- a/ld/configure
+++ b/ld/configure
@@ -680,6 +680,8 @@ WARN_WRITE_STRINGS
 NO_WERROR
 WARN_CFLAGS_FOR_BUILD
 WARN_CFLAGS
+ENABLE_LIBCTF_FALSE
+ENABLE_LIBCTF_TRUE
 installed_linker
 install_as_default
 TARGET_SYSTEM_ROOT_DEFINE
@@ -833,6 +835,7 @@ enable_new_dtags
 enable_relro
 enable_separate_code
 enable_default_hash_style
+enable_libctf
 enable_werror
 enable_build_warnings
 enable_nls
@@ -1501,6 +1504,7 @@ Optional Features:
   --enable-separate-code  enable -z separate-code in ELF linker by default
   --enable-default-hash-style={sysv,gnu,both}
                           use this default hash style
+  --enable-libctf         Handle .ctf type-info sections [default=yes]
   --enable-werror         treat compile warnings as errors
   --enable-build-warnings enable build-time compiler warnings
   --disable-nls           do not use Native Language Support
@@ -12032,7 +12036,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12035 "configure"
+#line 12039 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12138,7 +12142,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12141 "configure"
+#line 12145 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15915,6 +15919,33 @@ case "${enable_default_hash_style}" in
   *) ac_default_emit_gnu_hash=0 ;;
 esac
 
+ # Check whether --enable-libctf was given.
+if test "${enable_libctf+set}" = set; then :
+  enableval=$enable_libctf;
+      case "$enableval" in
+       yes|no) ;;
+       *) as_fn_error $? "Argument to enable/disable libctf must be yes or no" "$LINENO" 5 ;;
+      esac
+
+else
+  enable_libctf=yes
+fi
+
+
+if test "${enable_libctf}" = yes; then
+
+$as_echo "#define ENABLE_LIBCTF 1" >>confdefs.h
+
+fi
+ if test "${enable_libctf}" = yes; then
+  ENABLE_LIBCTF_TRUE=
+  ENABLE_LIBCTF_FALSE='#'
+else
+  ENABLE_LIBCTF_TRUE='#'
+  ENABLE_LIBCTF_FALSE=
+fi
+
+
 
 # Set the 'development' global.
 . $srcdir/../bfd/development.sh
@@ -17673,6 +17704,9 @@ else
   TESTBFDLIB="../bfd/.libs/libbfd.a"
   TESTCTFLIB="../libctf/.libs/libctf.a"
 fi
+if test "${enable_libctf}" = no; then
+    TESTCTFLIB=
+fi
 
 
 
@@ -17845,6 +17879,10 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then
   as_fn_error $? "conditional \"am__fastdepCXX\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${ENABLE_LIBCTF_TRUE}" && test -z "${ENABLE_LIBCTF_FALSE}"; then
+  as_fn_error $? "conditional \"ENABLE_LIBCTF\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
   as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/ld/configure.ac b/ld/configure.ac
index bdc167769e..0ef93dd9d8 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -212,6 +212,12 @@ case "${enable_default_hash_style}" in
   *) ac_default_emit_gnu_hash=0 ;;
 esac
 
+GCC_ENABLE([libctf], [yes], [], [Handle .ctf type-info sections])
+if test "${enable_libctf}" = yes; then
+    AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])
+fi
+AM_CONDITIONAL(ENABLE_LIBCTF, test "${enable_libctf}" = yes)
+
 AM_BINUTILS_WARNINGS
 
 AM_LC_MESSAGES
@@ -496,6 +502,9 @@ else
   TESTBFDLIB="../bfd/.libs/libbfd.a"
   TESTCTFLIB="../libctf/.libs/libctf.a"
 fi
+if test "${enable_libctf}" = no; then
+    TESTCTFLIB=
+fi
 AC_SUBST(TESTBFDLIB)
 AC_SUBST(TESTCTFLIB)
 
diff --git a/ld/ldelfgen.c b/ld/ldelfgen.c
index 682872f9dc..d5de1eb10c 100644
--- a/ld/ldelfgen.c
+++ b/ld/ldelfgen.c
@@ -75,6 +75,7 @@ ldelf_map_segments (bfd_boolean need_layout)
     einfo (_("%F%P: looping in map_segments"));
 }
 
+#ifdef ENABLE_LIBCTF
 /* We want to emit CTF early if and only if we are not targetting ELF with this
    invocation.  */
 
@@ -184,3 +185,16 @@ ldelf_examine_strtab_for_ctf
  "cost: %s\n"), ctf_errmsg (ctf_errno (ctf_output)));
     }
 }
+#else
+extern int ldelf_emit_ctf_early (void)
+{
+  return 0;
+}
+
+extern void ldelf_examine_strtab_for_ctf
+  (struct ctf_file *ctf_output ATTRIBUTE_UNUSED,
+   struct elf_sym_strtab *syms ATTRIBUTE_UNUSED,
+   bfd_size_type symcount ATTRIBUTE_UNUSED,
+   struct elf_strtab_hash *symstrtab ATTRIBUTE_UNUSED)
+{}
+#endif
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 05ea0c881f..c958b48097 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -129,7 +129,9 @@ bfd_boolean delete_output_file_on_failure = FALSE;
 struct lang_phdr *lang_phdr_list;
 struct lang_nocrossrefs *nocrossref_list;
 struct asneeded_minfo **asneeded_list_tail;
+#ifdef ENABLE_LIBCTF
 static ctf_file_t *ctf_output;
+#endif
 
  /* Functions that traverse the linker script and might evaluate
     DEFINED() need to increment this at the start of the traversal.  */
@@ -3612,6 +3614,7 @@ open_input_bfds (lang_statement_union_type *s, enum open_bfd_mode mode)
     einfo ("%F");
 }
 
+#ifdef ENABLE_LIBCTF
 /* Open the CTF sections in the input files with libctf: if any were opened,
    create a fake input file that we'll write the merged CTF data to later
    on.  */
@@ -3791,6 +3794,38 @@ ldlang_write_ctf_late (void)
 
   lang_write_ctf (1);
 }
+#else
+static void
+ldlang_open_ctf (void)
+{
+  LANG_FOR_EACH_INPUT_STATEMENT (file)
+    {
+      asection *sect;
+
+      /* If built without CTF, warn and delete all CTF sections from the output.
+ (The alternative would be to simply concatenate them, which does not
+ yield a valid CTF section.)  */
+
+      if ((sect = bfd_get_section_by_name (file->the_bfd, ".ctf")) != NULL)
+ {
+    einfo (_("%P: warning: CTF section in `%pI' not linkable: "
+     "%P was built without support for CTF\n"), file);
+    sect->size = 0;
+    sect->flags |= SEC_EXCLUDE;
+ }
+    }
+}
+
+static void lang_merge_ctf (void) {}
+void
+ldlang_ctf_apply_strsym (struct elf_sym_strtab *syms ATTRIBUTE_UNUSED,
+ bfd_size_type symcount ATTRIBUTE_UNUSED,
+ struct elf_strtab_hash *symstrtab ATTRIBUTE_UNUSED)
+{
+}
+static void lang_write_ctf (int late ATTRIBUTE_UNUSED) {}
+void ldlang_write_ctf_late (void) {}
+#endif
 
 /* Add the supplied name to the symbol table as an undefined reference.
    This is a two step process as the symbol table doesn't even exist at
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 02/11] libctf: create: non-root-visible types should not appear in name tables

Nick Alcock
In reply to this post by Nick Alcock
We were accidentally interning newly-added and newly-opened
non-root-visible types into name tables, and removing names from name
tables when such types were removed.  This is very wrong: the whole
point of non-root-visible types is they do not go in name tables and
cannot be looked up by name.  This bug made non-root-visible types
basically identical to root-visible types, right back to the earliest
days of libctf in the Solaris era.
---
 libctf/ctf-create.c | 19 ++++++++++---------
 libctf/ctf-impl.h   |  2 +-
 libctf/ctf-open.c   | 37 ++++++++++++++++++++++++++++++-------
 3 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index fa40100c77..ff5fca353f 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -597,13 +597,13 @@ ctf_name_table (ctf_file_t *fp, int kind)
 }
 
 int
-ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int kind)
+ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int flag, int kind)
 {
   const char *name;
   if (ctf_dynhash_insert (fp->ctf_dthash, (void *) dtd->dtd_type, dtd) < 0)
     return -1;
 
-  if (dtd->dtd_data.ctt_name
+  if (flag == CTF_ADD_ROOT && dtd->dtd_data.ctt_name
       && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL)
     {
       if (ctf_dynhash_insert (ctf_name_table (fp, kind)->ctn_writable,
@@ -646,7 +646,8 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
     }
 
   if (dtd->dtd_data.ctt_name
-      && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL)
+      && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL
+      && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info))
     {
       ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable,
   name);
@@ -762,7 +763,8 @@ ctf_rollback (ctf_file_t *fp, ctf_snapshot_id_t id)
       kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info);
 
       if (dtd->dtd_data.ctt_name
-  && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL)
+  && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL
+  && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info))
  {
   ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable,
       name);
@@ -831,7 +833,7 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind,
       return (ctf_set_errno (fp, EAGAIN));
     }
 
-  if (ctf_dtd_insert (fp, dtd, kind) < 0)
+  if (ctf_dtd_insert (fp, dtd, flag, kind) < 0)
     {
       free (dtd);
       return CTF_ERR; /* errno is set for us.  */
@@ -1094,8 +1096,7 @@ ctf_add_struct_sized (ctf_file_t *fp, uint32_t flag, const char *name,
   ctf_dtdef_t *dtd;
   ctf_id_t type = 0;
 
-  /* Promote forwards to structs.  */
-
+  /* Promote root-visible forwards to structs.  */
   if (name != NULL)
     type = ctf_lookup_by_rawname (fp, CTF_K_STRUCT, name);
 
@@ -1132,7 +1133,7 @@ ctf_add_union_sized (ctf_file_t *fp, uint32_t flag, const char *name,
   ctf_dtdef_t *dtd;
   ctf_id_t type = 0;
 
-  /* Promote forwards to unions.  */
+  /* Promote root-visible forwards to unions.  */
   if (name != NULL)
     type = ctf_lookup_by_rawname (fp, CTF_K_UNION, name);
 
@@ -1168,7 +1169,7 @@ ctf_add_enum (ctf_file_t *fp, uint32_t flag, const char *name)
   ctf_dtdef_t *dtd;
   ctf_id_t type = 0;
 
-  /* Promote forwards to enums.  */
+  /* Promote root-visible forwards to enums.  */
   if (name != NULL)
     type = ctf_lookup_by_rawname (fp, CTF_K_ENUM, name);
 
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index 6040457e36..a720859a12 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -399,7 +399,7 @@ extern void ctf_list_prepend (ctf_list_t *, void *);
 extern void ctf_list_delete (ctf_list_t *, void *);
 extern int ctf_list_empty_p (ctf_list_t *lp);
 
-extern int ctf_dtd_insert (ctf_file_t *, ctf_dtdef_t *, int);
+extern int ctf_dtd_insert (ctf_file_t *, ctf_dtdef_t *, int flag, int kind);
 extern void ctf_dtd_delete (ctf_file_t *, ctf_dtdef_t *);
 extern ctf_dtdef_t *ctf_dtd_lookup (const ctf_file_t *, ctf_id_t);
 extern ctf_dtdef_t *ctf_dynamic_type (const ctf_file_t *, ctf_id_t);
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 7fb289af56..076a3cc708 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -765,7 +765,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
   for (id = 1, tp = tbuf; tp < tend; xp++, id++)
     {
       unsigned short kind = LCTF_INFO_KIND (fp, tp->ctt_info);
-      unsigned short flag = LCTF_INFO_ISROOT (fp, tp->ctt_info);
+      unsigned short isroot = LCTF_INFO_ISROOT (fp, tp->ctt_info);
       unsigned long vlen = LCTF_INFO_VLEN (fp, tp->ctt_info);
       ssize_t size, increment, vbytes;
 
@@ -787,7 +787,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
 
   if (((ctf_hash_lookup_type (fp->ctf_names.ctn_readonly,
       fp, name)) == 0)
-      || (flag & CTF_ADD_ROOT))
+      || isroot)
     {
       err = ctf_hash_define_type (fp->ctf_names.ctn_readonly, fp,
   LCTF_INDEX_TO_TYPE (fp, id, child),
@@ -804,6 +804,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
   break;
 
  case CTF_K_FUNCTION:
+  if (!isroot)
+    break;
+
   err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp,
       LCTF_INDEX_TO_TYPE (fp, id, child),
       tp->ctt_name);
@@ -812,6 +815,12 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
   break;
 
  case CTF_K_STRUCT:
+  if (size >= CTF_LSTRUCT_THRESH)
+    nlstructs++;
+
+  if (!isroot)
+    break;
+
   err = ctf_hash_define_type (fp->ctf_structs.ctn_readonly, fp,
       LCTF_INDEX_TO_TYPE (fp, id, child),
       tp->ctt_name);
@@ -819,23 +828,27 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
   if (err != 0)
     return err;
 
-  if (size >= CTF_LSTRUCT_THRESH)
-    nlstructs++;
   break;
 
  case CTF_K_UNION:
+  if (size >= CTF_LSTRUCT_THRESH)
+    nlunions++;
+
+  if (!isroot)
+    break;
+
   err = ctf_hash_define_type (fp->ctf_unions.ctn_readonly, fp,
       LCTF_INDEX_TO_TYPE (fp, id, child),
       tp->ctt_name);
 
   if (err != 0)
     return err;
-
-  if (size >= CTF_LSTRUCT_THRESH)
-    nlunions++;
   break;
 
  case CTF_K_ENUM:
+  if (!isroot)
+    break;
+
   err = ctf_hash_define_type (fp->ctf_enums.ctn_readonly, fp,
       LCTF_INDEX_TO_TYPE (fp, id, child),
       tp->ctt_name);
@@ -845,6 +858,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
   break;
 
  case CTF_K_TYPEDEF:
+  if (!isroot)
+    break;
+
   err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp,
       LCTF_INDEX_TO_TYPE (fp, id, child),
       tp->ctt_name);
@@ -855,6 +871,10 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
  case CTF_K_FORWARD:
   {
     ctf_names_t *np = ctf_name_table (fp, tp->ctt_type);
+
+    if (!isroot)
+      break;
+
     /* Only insert forward tags into the given hash if the type or tag
        name is not already present.  */
     if (ctf_hash_lookup_type (np->ctn_readonly, fp, name) == 0)
@@ -881,6 +901,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
  case CTF_K_VOLATILE:
  case CTF_K_CONST:
  case CTF_K_RESTRICT:
+  if (!isroot)
+    break;
+
   err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp,
       LCTF_INDEX_TO_TYPE (fp, id, child),
       tp->ctt_name);
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 03/11] libctf: create: don't add forwards if the type added already exists

Nick Alcock
In reply to this post by Nick Alcock
This is what ctf_add_forward is documented to do, but it's not what it
actually does: the code is quite happy to add forwards that duplicate
existing structs, etc.

This is obviously wrong and breaks both the nondeduplicating linker
and the upcoming deduplicator, as well as allowing ordinary callers of
ctf_add_type to corrupt the dictionary by just adding the same root-
visible forward more than once.
---
 libctf/ctf-create.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index ff5fca353f..1099fd3a2c 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -1229,7 +1229,10 @@ ctf_add_forward (ctf_file_t *fp, uint32_t flag, const char *name,
   if (name != NULL)
     type = ctf_lookup_by_rawname (fp, kind, name);
 
-  if ((type = ctf_add_generic (fp, flag, name, CTF_K_FORWARD,&dtd)) == CTF_ERR)
+  if (type)
+    return type;
+
+  if ((type = ctf_add_generic (fp, flag, name, CTF_K_FORWARD, &dtd)) == CTF_ERR)
     return CTF_ERR; /* errno is set for us.  */
 
   dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_FORWARD, flag, 0);
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 04/11] libctf: create: ctf_add_type should hand back already-added non-SoUs

Nick Alcock
In reply to this post by Nick Alcock
When we add a type from a dictionary and then try to add it again, we
should hand it back unchanged unless it is a structure, union or enum
with a different number of members.  That's what the comment says we do.

Instead, we hand it back unchanged *only* if it is a structure, union or
enum with the same number of members: non-structs, unions and enums are
unconditionally added.  This causes extreme type bloating and (in
conjunction with the bug fixed by the next commit) can easily lead to
the same type being mistakenly added to a dictionary more than once
(which, for forwards, was not banned and led to dictionary corruption).
---
 libctf/ctf-create.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 1099fd3a2c..fd7d553a6c 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -1665,13 +1665,17 @@ ctf_add_type_internal (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type
  kind and (if a struct or union) has the same number of members, hand it
  straight back.  */
 
-      if ((ctf_type_kind_unsliced (tmp_fp, tmp) == (int) kind)
-  && (kind == CTF_K_STRUCT || kind == CTF_K_UNION
-      || kind == CTF_K_ENUM))
+      if (ctf_type_kind_unsliced (tmp_fp, tmp) == (int) kind)
  {
-  if ((dst_tp = ctf_lookup_by_id (&tmp_fp, dst_type)) != NULL)
-    if (vlen == LCTF_INFO_VLEN (tmp_fp, dst_tp->ctt_info))
-      return tmp;
+  if (kind == CTF_K_STRUCT || kind == CTF_K_UNION
+      || kind == CTF_K_ENUM)
+    {
+      if ((dst_tp = ctf_lookup_by_id (&tmp_fp, dst_type)) != NULL)
+ if (vlen == LCTF_INFO_VLEN (tmp_fp, dst_tp->ctt_info))
+  return tmp;
+    }
+  else
+    return tmp;
  }
     }
 
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 05/11] libctf: create: forwards are always in the namespace of their referent

Nick Alcock
In reply to this post by Nick Alcock
The C namespace a forward is located in is always the same as the
namespace of the corresponding complete type: 'struct foo' is in the
struct namespace and does not collide with, say, 'union foo'.

libctf allowed for this in many places, but inconsistent: in particular,
forward *addition* never allowed for this, and was interning forwards in
the default namespace, which is always wrong, since you can only forward
structs, unions and enums, all of which are in their own namespaces in
C.

Forward removal needs corresponding adjustment to remove the names form
the right namespace, as does ctf_rollback.
---
 libctf/ctf-create.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index fd7d553a6c..a63c213d33 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -622,6 +622,7 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
 {
   ctf_dmdef_t *dmd, *nmd;
   int kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info);
+  int name_kind = kind;
   const char *name;
 
   ctf_dynhash_remove (fp->ctf_dthash, (void *) dtd->dtd_type);
@@ -643,13 +644,16 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
     case CTF_K_FUNCTION:
       free (dtd->dtd_u.dtu_argv);
       break;
+    case CTF_K_FORWARD:
+      name_kind = dtd->dtd_data.ctt_type;
+      break;
     }
 
   if (dtd->dtd_data.ctt_name
       && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL
       && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info))
     {
-      ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable,
+      ctf_dynhash_remove (ctf_name_table (fp, name_kind)->ctn_writable,
   name);
       ctf_str_remove_ref (fp, name, &dtd->dtd_data.ctt_name);
     }
@@ -761,6 +765,8 @@ ctf_rollback (ctf_file_t *fp, ctf_snapshot_id_t id)
  continue;
 
       kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info);
+      if (kind == CTF_K_FORWARD)
+ kind = dtd->dtd_data.ctt_type;
 
       if (dtd->dtd_data.ctt_name
   && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL
@@ -1232,7 +1238,7 @@ ctf_add_forward (ctf_file_t *fp, uint32_t flag, const char *name,
   if (type)
     return type;
 
-  if ((type = ctf_add_generic (fp, flag, name, CTF_K_FORWARD, &dtd)) == CTF_ERR)
+  if ((type = ctf_add_generic (fp, flag, name, kind, &dtd)) == CTF_ERR)
     return CTF_ERR; /* errno is set for us.  */
 
   dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_FORWARD, flag, 0);
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 06/11] libctf, binutils: support CTF archives like objdump

Nick Alcock
In reply to this post by Nick Alcock
objdump and readelf have one major CTF-related behavioural difference:
objdump can read .ctf sections that contain CTF archives and extract and
dump their members, while readelf cannot.  Since the linker often emits
CTF archives, this means that readelf intermittently and (from the
user's perspective) randomly fails to read CTF in files that ld emits,
with a confusing error message wrongly claiming that the CTF content is
corrupt.  This is purely because the archive-opening code in libctf was
needlessly tangled up with the BFD code, so readelf couldn't use it.

Here, we disentangle it, moving ctf_new_archive_internal from
ctf-open-bfd.c into ctf-archive.c and merging it with the helper
function in ctf-archive.c it was already using.  We add a new public API
function ctf_arc_bufopen, that looks very like ctf_bufopen but returns
an archive given suitable section data rather than a ctf_file_t: the
archive is a ctf_archive_t, so it can be called on raw CTF dictionaries
(with no archive present) and will return a single-member synthetic
"archive".

There is a tiny lifetime tweak here: before now, the archive code could
assume that the symbol section in the ctf_archive_internal wrapper
structure was always owned by BFD if it was present and should always be
freed: now, the caller can pass one in via ctf_arc_bufopen, wihch has
the usual lifetime rules for such sections (caller frees): so we add an
extra field to track whether this is an internal call from ctf-open-bfd,
in which case we still free the symbol section.

include/
        * ctf-api.h (ctf_arc_bufopen): New.
libctf/
        * ctf-impl.h (ctf_new_archive_internal): Declare.
        (ctf_arc_bufopen): Remove.
        (ctf_archive_internal) <ctfi_free_symsect>: New.
        * ctf-archive.c (ctf_arc_close): Use it.
        (ctf_arc_bufopen): Fuse into...
        (ctf_new_archive_internal): ... this, moved across from...
        * ctf-open-bfd.c: ... here.
        (ctf_bfdopen_ctfsect): Use ctf_arc_bufopen.
        * libctf.ver: Add it.
binutils/
        * readelf.c (dump_section_as_ctf): Support .ctf archives using
        ctf_arc_bufopen.  Automatically load the .ctf member of such
        archives as the parent of all other members, unless specifically
        overridden via --ctf-parent.  Split out dumping code into...
        (dump_ctf_archive_member): ... here, as in objdump, and call
        it once per archive member.
        (dump_ctf_indent_lines): Code style fix.
---
 binutils/ChangeLog    |  10 ++++
 binutils/readelf.c    | 110 +++++++++++++++++++++++++++++-------------
 include/ChangeLog     |   4 ++
 include/ctf-api.h     |   4 ++
 libctf/ChangeLog      |  12 +++++
 libctf/ctf-archive.c  |  76 ++++++++++++++++++++++++-----
 libctf/ctf-impl.h     |   6 ++-
 libctf/ctf-open-bfd.c |  68 +++-----------------------
 libctf/libctf.ver     |   1 +
 9 files changed, 182 insertions(+), 109 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 4490679ca8..86594f2173 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,13 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ * readelf.c (dump_section_as_ctf): Support .ctf archives using
+ ctf_arc_bufopen.  Automatically load the .ctf member of such
+ archives as the parent of all other members, unless specifically
+ overridden via --ctf-parent.  Split out dumping code into...
+ (dump_ctf_archive_member): ... here, as in objdump, and call
+ it once per archive member.
+ (dump_ctf_indent_lines): Code style fix.
+
 2019-09-30  Nick Alcock  <[hidden email]>
 
  * configure.ac [--enable-libctf]: New, default yes.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index e92c3ce1ed..e3aaa70dc2 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -13920,8 +13920,9 @@ shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
    it is passed, or a pointer to newly-allocated storage, in which case
    dump_ctf() will free it when it no longer needs it.  */
 
-static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
-    char *s, void *arg)
+static char *
+dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
+       char *s, void *arg)
 {
   const char *blanks = arg;
   char *new_s;
@@ -13931,6 +13932,55 @@ static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
   return new_s;
 }
 
+/* Dump one CTF archive member.  */
+
+static int
+dump_ctf_archive_member (ctf_file_t *ctf, const char *name, void *arg)
+{
+  ctf_file_t *parent = (ctf_file_t *) arg;
+  const char *things[] = {"Header", "Labels", "Data objects",
+  "Function objects", "Variables", "Types", "Strings",
+  ""};
+  const char **thing;
+  size_t i;
+
+  /* Only print out the name of non-default-named archive members.
+     The name .ctf appears everywhere, even for things that aren't
+     really archives, so printing it out is liable to be confusing.
+
+     The parent, if there is one, is the default-owned archive member:
+     avoid importing it into itself.  (This does no harm, but looks
+     confusing.)  */
+
+  if (strcmp (name, ".ctf") != 0)
+    {
+      printf (_("\nCTF archive member: %s:\n"), name);
+      ctf_import (ctf, parent);
+    }
+
+  for (i = 0, thing = things; *thing[0]; thing++, i++)
+    {
+      ctf_dump_state_t *s = NULL;
+      char *item;
+
+      printf ("\n  %s:\n", *thing);
+      while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
+       (void *) "    ")) != NULL)
+ {
+  printf ("%s\n", item);
+  free (item);
+ }
+
+      if (ctf_errno (ctf))
+ {
+  error (_("Iteration failed: %s, %s\n"), *thing,
+ ctf_errmsg (ctf_errno (ctf)));
+  return 1;
+ }
+    }
+  return 0;
+}
+
 static bfd_boolean
 dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
 {
@@ -13944,16 +13994,12 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   ctf_sect_t       ctfsect, symsect, strsect, parentsect;
   ctf_sect_t *       symsectp = NULL;
   ctf_sect_t *       strsectp = NULL;
-  ctf_file_t *       ctf = NULL;
-  ctf_file_t *       parent = NULL;
+  ctf_archive_t *      ctfa = NULL;
+  ctf_archive_t *      parenta = NULL, *lookparent;
+  ctf_file_t *         parent = NULL;
 
-  const char *things[] = {"Header", "Labels", "Data objects",
-  "Function objects", "Variables", "Types", "Strings",
-  ""};
-  const char **thing;
   int err;
   bfd_boolean ret = FALSE;
-  size_t i;
 
   shdr_to_ctf_sect (&ctfsect, section, filedata);
   data = get_section_contents (section, filedata);
@@ -14012,9 +14058,11 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
       parentsect.cts_data = parentdata;
     }
 
-  /* Load the CTF file and dump it.  */
+  /* Load the CTF file and dump it.  It may be a raw CTF section, or an archive:
+     libctf papers over the difference, so we can pretend it is always an
+     archive.  Possiblyopen the parent as well, if one was specified.  */
 
-  if ((ctf = ctf_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
+  if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
     {
       error (_("CTF open failure: %s\n"), ctf_errmsg (err));
       goto fail;
@@ -14022,13 +14070,24 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
 
   if (parentdata)
     {
-      if ((parent = ctf_bufopen (&parentsect, symsectp, strsectp, &err)) == NULL)
+      if ((parenta = ctf_arc_bufopen (&parentsect, symsectp, strsectp,
+      &err)) == NULL)
  {
   error (_("CTF open failure: %s\n"), ctf_errmsg (err));
   goto fail;
  }
+      lookparent = parenta;
+    }
+  else
+    lookparent = ctfa;
 
-      ctf_import (ctf, parent);
+  /* Assume that the applicable parent archive member is the default one.
+     (This is what all known implementations are expected to do, if they
+     put CTFs and their parents in archives together.)  */
+  if ((parent = ctf_arc_open_by_name (lookparent, NULL, &err)) == NULL)
+    {
+      error (_("CTF open failure: %s\n"), ctf_errmsg (err));
+      goto fail;
     }
 
   ret = TRUE;
@@ -14036,30 +14095,13 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   printf (_("\nDump of CTF section '%s':\n"),
   printable_section_name (filedata, section));
 
-  for (i = 0, thing = things; *thing[0]; thing++, i++)
-    {
-      ctf_dump_state_t *s = NULL;
-      char *item;
-
-      printf ("\n  %s:\n", *thing);
-      while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
-       (void *) "    ")) != NULL)
- {
-  printf ("%s\n", item);
-  free (item);
- }
-
-      if (ctf_errno (ctf))
- {
-  error (_("Iteration failed: %s, %s\n"), *thing,
-   ctf_errmsg (ctf_errno (ctf)));
-  ret = FALSE;
- }
-    }
+  if (ctf_archive_iter (ctfa, dump_ctf_archive_member, parent) != 0)
+    ret = FALSE;
 
  fail:
-  ctf_file_close (ctf);
   ctf_file_close (parent);
+  ctf_close (ctfa);
+  ctf_close (parenta);
   free (parentdata);
   free (data);
   free (symdata);
diff --git a/include/ChangeLog b/include/ChangeLog
index 1444cc9146..03f4d626b1 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,7 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ * ctf-api.h (ctf_arc_bufopen): New.
+
 2019-12-12  Luis Machado  <[hidden email]>
 
  * diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_FUNCTION). Remove
diff --git a/include/ctf-api.h b/include/ctf-api.h
index d15b734210..fb494b2021 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -263,6 +263,10 @@ extern void ctf_close (ctf_archive_t *);
 extern ctf_sect_t ctf_getdatasect (const ctf_file_t *);
 extern ctf_archive_t *ctf_get_arc (const ctf_file_t *);
 extern ctf_archive_t *ctf_arc_open (const char *, int *);
+extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *,
+       const ctf_sect_t *,
+       const ctf_sect_t *,
+       int *);
 extern void ctf_arc_close (ctf_archive_t *);
 extern ctf_file_t *ctf_arc_open_by_name (const ctf_archive_t *,
  const char *, int *);
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index ea34bae856..3f536cee86 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,15 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ * ctf-impl.h (ctf_new_archive_internal): Declare.
+ (ctf_arc_bufopen): Remove.
+ (ctf_archive_internal) <ctfi_free_symsect>: New.
+ * ctf-archive.c (ctf_arc_close): Use it.
+ (ctf_arc_bufopen): Fuse into...
+ (ctf_new_archive_internal): ... this, moved across from...
+ * ctf-open-bfd.c: ... here.
+ (ctf_bfdopen_ctfsect): Use ctf_arc_bufopen.
+ * libctf.ver: Add it.
+
 2019-10-16  Simon Marchi  <[hidden email]>
 
  * swap.h (bswap_16, bswap_32, bswap_64): Make static.
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index ed1483ade7..bf3e32f128 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -343,21 +343,71 @@ search_modent_by_name (const void *key, const void *ent)
   return strcmp (k, &search_nametbl[le64toh (v->name_offset)]);
 }
 
-/* A trivial wrapper: open a CTF archive, from data in a buffer (which the
-   caller must preserve until ctf_arc_close() time).  Returns the archive, or
-   NULL and an error in *err (if not NULL).  */
-struct ctf_archive *
-ctf_arc_bufopen (const void *buf, size_t size _libctf_unused_, int *errp)
+/* Make a new struct ctf_archive_internal wrapper for a ctf_archive or a
+   ctf_file.  Closes ARC and/or FP on error.  Arrange to free the SYMSECT or
+   STRSECT, as needed, on close.  */
+
+struct ctf_archive_internal *
+ctf_new_archive_internal (int is_archive, struct ctf_archive *arc,
+  ctf_file_t *fp, const ctf_sect_t *symsect,
+  const ctf_sect_t *strsect,
+  int *errp)
 {
-  struct ctf_archive *arc = (struct ctf_archive *) buf;
+  struct ctf_archive_internal *arci;
 
-  if (le64toh (arc->ctfa_magic) != CTFA_MAGIC)
+  if ((arci = calloc (1, sizeof (struct ctf_archive_internal))) == NULL)
     {
-      if (errp)
- *errp = ECTF_FMT;
-      return NULL;
+      if (is_archive)
+ ctf_arc_close_internal (arc);
+      else
+ ctf_file_close (fp);
+      return (ctf_set_open_errno (errp, errno));
     }
-  return arc;
+  arci->ctfi_is_archive = is_archive;
+  if (is_archive)
+    arci->ctfi_archive = arc;
+  else
+    arci->ctfi_file = fp;
+  if (symsect)
+     memcpy (&arci->ctfi_symsect, symsect, sizeof (struct ctf_sect));
+  if (strsect)
+     memcpy (&arci->ctfi_strsect, strsect, sizeof (struct ctf_sect));
+  arci->ctfi_free_symsect = 0;
+
+  return arci;
+}
+
+/* Open a CTF archive or dictionary from data in a buffer (which the caller must
+   preserve until ctf_arc_close() time).  Returns the archive, or NULL and an
+   error in *err (if not NULL).  */
+ctf_archive_t *
+ctf_arc_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
+ const ctf_sect_t *strsect, int *errp)
+{
+  struct ctf_archive *arc = NULL;
+  int is_archive;
+  ctf_file_t *fp = NULL;
+
+  if (ctfsect->cts_size > sizeof (uint64_t) &&
+      ((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC))
+    {
+      /* The archive is mmappable, so this operation is trivial.  */
+
+      is_archive = 1;
+      arc = (struct ctf_archive *) ctfsect->cts_data;
+    }
+  else
+    {
+      is_archive = 0;
+      if ((fp = ctf_bufopen (ctfsect, symsect, strsect, errp)) == NULL)
+ {
+  ctf_dprintf ("ctf_internal_open(): cannot open CTF: %s\n",
+       ctf_errmsg (*errp));
+  return NULL;
+ }
+    }
+  return ctf_new_archive_internal (is_archive, arc, fp, symsect, strsect,
+   errp);
 }
 
 /* Open a CTF archive.  Returns the archive, or NULL and an error in *err (if
@@ -436,8 +486,8 @@ ctf_arc_close (ctf_archive_t *arc)
     ctf_arc_close_internal (arc->ctfi_archive);
   else
     ctf_file_close (arc->ctfi_file);
-  free ((void *) arc->ctfi_symsect.cts_data);
-  /* Do not free the ctfi_strsect: it is bound to the bfd.  */
+  if (arc->ctfi_free_symsect)
+    free ((void *) arc->ctfi_symsect.cts_data);
   free (arc->ctfi_data);
   if (arc->ctfi_bfd_close)
     arc->ctfi_bfd_close (arc);
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index a720859a12..de855b5883 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -309,6 +309,7 @@ struct ctf_archive_internal
   struct ctf_archive *ctfi_archive;
   ctf_sect_t ctfi_symsect;
   ctf_sect_t ctfi_strsect;
+  int ctfi_free_symsect;
   void *ctfi_data;
   bfd *ctfi_abfd;    /* Optional source of section data.  */
   void (*ctfi_bfd_close) (struct ctf_archive_internal *);
@@ -435,8 +436,11 @@ extern void ctf_str_rollback (ctf_file_t *, ctf_snapshot_id_t);
 extern void ctf_str_purge_refs (ctf_file_t *);
 extern ctf_strs_writable_t ctf_str_write_strtab (ctf_file_t *);
 
+extern struct ctf_archive_internal *ctf_new_archive_internal
+ (int is_archive, struct ctf_archive *arc,
+ ctf_file_t *fp, const ctf_sect_t *symsect,
+ const ctf_sect_t *strsect, int *errp);
 extern struct ctf_archive *ctf_arc_open_internal (const char *, int *);
-extern struct ctf_archive *ctf_arc_bufopen (const void *, size_t, int *);
 extern void ctf_arc_close_internal (struct ctf_archive *);
 extern void *ctf_set_open_errno (int *, int);
 extern unsigned long ctf_set_errno (ctf_file_t *, int);
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
index d17b72d2f0..b40d3778d0 100644
--- a/libctf/ctf-open-bfd.c
+++ b/libctf/ctf-open-bfd.c
@@ -32,40 +32,6 @@
 
 #include "elf-bfd.h"
 
-/* Make a new struct ctf_archive_internal wrapper for a ctf_archive or a
-   ctf_file.  Closes ARC and/or FP on error.  Arrange to free the SYMSECT or
-   STRSECT, as needed, on close (though the STRSECT interior is bound to the bfd
-   * and is not actually freed by this machinery).  */
-
-static struct ctf_archive_internal *
-ctf_new_archive_internal (int is_archive, struct ctf_archive *arc,
-  ctf_file_t *fp, const ctf_sect_t *symsect,
-  const ctf_sect_t *strsect,
-  int *errp)
-{
-  struct ctf_archive_internal *arci;
-
-  if ((arci = calloc (1, sizeof (struct ctf_archive_internal))) == NULL)
-    {
-      if (is_archive)
- ctf_arc_close_internal (arc);
-      else
- ctf_file_close (fp);
-      return (ctf_set_open_errno (errp, errno));
-    }
-  arci->ctfi_is_archive = is_archive;
-  if (is_archive)
-    arci->ctfi_archive = arc;
-  else
-    arci->ctfi_file = fp;
-  if (symsect)
-     memcpy (&arci->ctfi_symsect, symsect, sizeof (struct ctf_sect));
-  if (strsect)
-     memcpy (&arci->ctfi_strsect, strsect, sizeof (struct ctf_sect));
-
-  return arci;
-}
-
 /* Free the BFD bits of a CTF file on ctf_arc_close().  */
 
 static void
@@ -107,6 +73,7 @@ ctf_bfdopen (struct bfd *abfd, int *errp)
 
   if ((arc = ctf_bfdopen_ctfsect (abfd, &ctfsect, errp)) != NULL)
     {
+      /* This frees the cts_data later.  */
       arc->ctfi_data = (void *) ctfsect.cts_data;
       return arc;
     }
@@ -116,20 +83,16 @@ ctf_bfdopen (struct bfd *abfd, int *errp)
 }
 
 /* Open a CTF file given the specified BFD and CTF section (which may contain a
-   CTF archive or a file).  Takes ownership of the ctfsect, and frees it
-   later.  */
+   CTF archive or a file).  */
 
 ctf_archive_t *
 ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
      const ctf_sect_t *ctfsect, int *errp)
 {
-  struct ctf_archive *arc = NULL;
   ctf_archive_t *arci;
-  ctf_file_t *fp = NULL;
   ctf_sect_t *symsectp = NULL;
   ctf_sect_t *strsectp = NULL;
   const char *bfderrstr = NULL;
-  int is_archive;
 
 #ifdef HAVE_BFD_ELF
   ctf_sect_t symsect, strsect;
@@ -192,30 +155,13 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
     }
 #endif
 
-  if (ctfsect->cts_size > sizeof (uint64_t) &&
-      ((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC))
-    {
-      is_archive = 1;
-      if ((arc = ctf_arc_bufopen ((void *) ctfsect->cts_data,
-  ctfsect->cts_size, errp)) == NULL)
- goto err_free_str;
-    }
-  else
+  arci = ctf_arc_bufopen (ctfsect, symsectp, strsectp, errp);
+  if (arci)
     {
-      is_archive = 0;
-      if ((fp = ctf_bufopen (ctfsect, symsectp, strsectp, errp)) == NULL)
- {
-  ctf_dprintf ("ctf_internal_open(): cannot open CTF: %s\n",
-       ctf_errmsg (*errp));
-  goto err_free_str;
- }
+      /* Request freeing of the symsect.  */
+      arci->ctfi_free_symsect = 1;
+      return arci;
     }
-  arci = ctf_new_archive_internal (is_archive, arc, fp, symsectp, strsectp,
-   errp);
-
-  if (arci)
-    return arci;
- err_free_str: ;
 #ifdef HAVE_BFD_ELF
  err_free_sym:
   free (symtab);
diff --git a/libctf/libctf.ver b/libctf/libctf.ver
index a90f06ac9b..1b8c7f21d4 100644
--- a/libctf/libctf.ver
+++ b/libctf/libctf.ver
@@ -128,6 +128,7 @@ LIBCTF_1.0 {
  ctf_arc_write;
  ctf_arc_write_fd;
  ctf_arc_open;
+ ctf_arc_bufopen;
  ctf_arc_close;
  ctf_arc_open_by_name;
  ctf_arc_open_by_name_sections;
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 07/11] libiberty, include, libctf: Use bsearch_r to avoid nonportable __thread

Nick Alcock
In reply to this post by Nick Alcock
We do not AC_LIBOBJ bsearch_r at this point because as far as I can see
this obvious function is not implemented by anyone's libc.  We can
easily move it to AC_LIBOBJ later if it proves necessary.

        PR25120
include/
        * libiberty.h (bsearch_r): New.
libiberty/
        * bsearch_r.c: New file.
        * Makefile.in (CFILES): Add bsearch_r.c.
        (REQUIRED_OFILES): Add bsearch_r.o.
        (bsearch_r.$(objext)): New target.
libctf/
        * ctf-archive.c (search_nametbl): No longer global: declare...
        (ctf_arc_open_by_name_internal): ... here. Use bsearch_r.
        (search_modent_by_name): Take and use ARG for the nametbl.
---
 include/ChangeLog     |  5 +++
 include/libiberty.h   |  7 ++++
 libctf/ChangeLog      |  7 ++++
 libctf/ctf-archive.c  | 17 ++++----
 libiberty/ChangeLog   |  8 ++++
 libiberty/Makefile.in | 12 +++++-
 libiberty/bsearch_r.c | 92 +++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 138 insertions(+), 10 deletions(-)
 create mode 100644 libiberty/bsearch_r.c

diff --git a/include/ChangeLog b/include/ChangeLog
index 03f4d626b1..a84047c4bf 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * libiberty.h (bsearch_r): New.
+
 2019-12-16  Nick Alcock  <[hidden email]>
 
  * ctf-api.h (ctf_arc_bufopen): New.
diff --git a/include/libiberty.h b/include/libiberty.h
index 5747613502..4376e61f99 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -637,6 +637,13 @@ extern int pexecute (const char *, char * const *, const char *,
 
 extern int pwait (int, int *, int);
 
+/* Like bsearch, but takes and passes on an argument like qsort_r.  */
+
+extern void *bsearch_r (register const void *, const void *,
+ size_t, register size_t,
+ register int (*)(const void *, const void *, void *),
+ void *);
+
 #if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
 /* Like sprintf but provides a pointer to malloc'd storage, which must
    be freed by the caller.  */
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 3f536cee86..7b0e9e6fa7 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * ctf-archive.c (search_nametbl): No longer global: declare...
+ (ctf_arc_open_by_name_internal): ... here. Use bsearch_r.
+ (search_modent_by_name): Take and use ARG for the nametbl.
+
 2019-12-16  Nick Alcock  <[hidden email]>
 
  * ctf-impl.h (ctf_new_archive_internal): Declare.
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index bf3e32f128..050fe390e6 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -44,9 +44,6 @@ static int arc_mmap_writeout (int fd, void *header, size_t headersz,
       const char **errmsg);
 static int arc_mmap_unmap (void *header, size_t headersz, const char **errmsg);
 
-/* bsearch() internal state.  */
-static __thread char *search_nametbl;
-
 /* Write out a CTF archive to the start of the file referenced by the passed-in
    fd.  The entries in CTF_FILES are referenced by name: the names are passed in
    the names array, which must have CTF_FILES entries.
@@ -332,13 +329,14 @@ sort_modent_by_name (const void *one, const void *two, void *n)
  &nametbl[le64toh (b->name_offset)]);
 }
 
-/* bsearch() function to search for a given name in the sorted array of struct
+/* bsearch_r() function to search for a given name in the sorted array of struct
    ctf_archive_modents.  */
 static int
-search_modent_by_name (const void *key, const void *ent)
+search_modent_by_name (const void *key, const void *ent, void *arg)
 {
   const char *k = key;
   const struct ctf_archive_modent *v = ent;
+  const char *search_nametbl = arg;
 
   return strcmp (k, &search_nametbl[le64toh (v->name_offset)]);
 }
@@ -503,6 +501,7 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
        const char *name, int *errp)
 {
   struct ctf_archive_modent *modent;
+  const char *search_nametbl;
 
   if (name == NULL)
     name = _CTF_SECTION; /* The default name.  */
@@ -512,10 +511,10 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
   modent = (ctf_archive_modent_t *) ((char *) arc
      + sizeof (struct ctf_archive));
 
-  search_nametbl = (char *) arc + le64toh (arc->ctfa_names);
-  modent = bsearch (name, modent, le64toh (arc->ctfa_nfiles),
-    sizeof (struct ctf_archive_modent),
-    search_modent_by_name);
+  search_nametbl = (const char *) arc + le64toh (arc->ctfa_names);
+  modent = bsearch_r (name, modent, le64toh (arc->ctfa_nfiles),
+      sizeof (struct ctf_archive_modent),
+      search_modent_by_name, (void *) search_nametbl);
 
   /* This is actually a common case and normal operation: no error
      debug output.  */
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 95cb1525f2..6b6d47f7b5 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * bsearch_r.c: New file.
+ * Makefile.in (CFILES): Add bsearch_r.c.
+ (REQUIRED_OFILES): Add bsearch_r.o.
+ (bsearch_r.$(objext)): New target.
+
 2019-08-08  Martin Liska  <[hidden email]>
 
  PR bootstrap/91352
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index 0be45b4ae8..f14a6e1455 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -123,7 +123,7 @@ COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) \
 # CONFIGURED_OFILES and funcs in configure.ac.  Also run "make maint-deps"
 # to build the new rules.
 CFILES = alloca.c argv.c asprintf.c atexit.c \
- basename.c bcmp.c bcopy.c bsearch.c bzero.c \
+ basename.c bcmp.c bcopy.c bsearch.c bsearch_r.c bzero.c \
  calloc.c choose-temp.c clock.c concat.c cp-demangle.c \
  cp-demint.c cplus-dem.c crc32.c \
  d-demangle.c dwarfnames.c dyn-string.c \
@@ -167,6 +167,7 @@ REQUIRED_OFILES = \
  ./regex.$(objext) ./cplus-dem.$(objext) ./cp-demangle.$(objext) \
  ./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext) \
  ./argv.$(objext) \
+ ./bsearch_r.$(objext) \
  ./choose-temp.$(objext) ./concat.$(objext) \
  ./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext) \
  ./dwarfnames.$(objext) ./dyn-string.$(objext) \
@@ -597,6 +598,15 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
  else true; fi
  $(COMPILE.c) $(srcdir)/bsearch.c $(OUTPUT_OPTION)
 
+./bsearch_r.$(objext): $(srcdir)/bsearch_r.c config.h $(INCDIR)/ansidecl.h
+ if [ x"$(PICFLAG)" != x ]; then \
+  $(COMPILE.c) $(PICFLAG) $(srcdir)/bsearch_r.c -o pic/$@; \
+ else true; fi
+ if [ x"$(NOASANFLAG)" != x ]; then \
+  $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/bsearch_r.c -o noasan/$@; \
+ else true; fi
+ $(COMPILE.c) $(srcdir)/bsearch_r.c $(OUTPUT_OPTION)
+
 ./bzero.$(objext): $(srcdir)/bzero.c
  if [ x"$(PICFLAG)" != x ]; then \
   $(COMPILE.c) $(PICFLAG) $(srcdir)/bzero.c -o pic/$@; \
diff --git a/libiberty/bsearch_r.c b/libiberty/bsearch_r.c
new file mode 100644
index 0000000000..467631e44e
--- /dev/null
+++ b/libiberty/bsearch_r.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. [rescinded 22 July 1999]
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+
+@deftypefn Supplemental void* bsearch_r (const void *@var{key}, @
+  const void *@var{base}, size_t @var{nmemb}, size_t @var{size}, @
+  int (*@var{compar})(const void *, const void *, void *), void *@var{arg})
+
+Performs a search over an array of @var{nmemb} elements pointed to by
+@var{base} for a member that matches the object pointed to by @var{key}.
+The size of each member is specified by @var{size}.  The array contents
+should be sorted in ascending order according to the @var{compar}
+comparison function.  This routine should take two arguments pointing to
+the @var{key} and to an array member, in that order, and should return an
+integer less than, equal to, or greater than zero if the @var{key} object
+is respectively less than, matching, or greater than the array member.
+
+@end deftypefn
+
+*/
+
+#include "config.h"
+#include "ansidecl.h"
+#include <sys/types.h> /* size_t */
+#include <stdio.h>
+
+/*
+ * Perform a binary search.
+ *
+ * The code below is a bit sneaky.  After a comparison fails, we
+ * divide the work in half by moving either left or right. If lim
+ * is odd, moving left simply involves halving lim: e.g., when lim
+ * is 5 we look at item 2, so we change lim to 2 so that we will
+ * look at items 0 & 1.  If lim is even, the same applies.  If lim
+ * is odd, moving right again involes halving lim, this time moving
+ * the base up one item past p: e.g., when lim is 5 we change base
+ * to item 3 and make lim 2 so that we will look at items 3 and 4.
+ * If lim is even, however, we have to shrink it by one before
+ * halving: e.g., when lim is 4, we still looked at item 2, so we
+ * have to make lim 3, then halve, obtaining 1, so that we will only
+ * look at item 3.
+ */
+void *
+bsearch_r (register const void *key, const void *base0,
+   size_t nmemb, register size_t size,
+   register int (*compar)(const void *, const void *, void *),
+   void *arg)
+{
+ register const char *base = (const char *) base0;
+ register int lim, cmp;
+ register const void *p;
+
+ for (lim = nmemb; lim != 0; lim >>= 1) {
+ p = base + (lim >> 1) * size;
+ cmp = (*compar)(key, p, arg);
+ if (cmp == 0)
+ return (void *)p;
+ if (cmp > 0) { /* key > p: move right */
+ base = (const char *)p + size;
+ lim--;
+ } /* else move left */
+ }
+ return (NULL);
+}
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 08/11] libctf: work with compilers not supporting GNU C attributes

Nick Alcock
In reply to this post by Nick Alcock
The obvious fallback __attribute__ stanza was missing.

Thanks to Harald van Dijk.

        PR 25120
libctf/
        * ctf-impl.h (_libctf_printflike_): Add non-GNU-C fallback.
        (_libctf_unlikely_): Likewise.
        (_libctf_unused): Likewise.
        (_libctf_malloc_): Likewise.
---
 libctf/ChangeLog  | 8 ++++++++
 libctf/ctf-impl.h | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 7b0e9e6fa7..7550015cab 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * ctf-impl.h (_libctf_printflike_): Add non-GNU-C fallback.
+ (_libctf_unlikely_): Likewise.
+ (_libctf_unused): Likewise.
+ (_libctf_malloc_): Likewise.
+
 2019-12-16  Nick Alcock  <[hidden email]>
 
  PR libctf/25120
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index de855b5883..5a2ad464ae 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -59,6 +59,13 @@ extern "C"
 #define _libctf_unused_ __attribute__ ((__unused__))
 #define _libctf_malloc_ __attribute__((__malloc__))
 
+#else
+
+#define _libctf_printflike_(string_index,first_to_check)
+#define _libctf_unlikely_(x) (x)
+#define _libctf_unused_
+#define _libctf_malloc_
+
 #endif
 
 /* libctf in-memory state.  */
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 09/11] libctf, elfcpp, gold: do not assume that <byteswap.h> contains bswap_*

Nick Alcock
In reply to this post by Nick Alcock
At least one C library (uclibc-ng) defines some of these only when
the compiler is GCC.  We might as well test for all three cases and
handle any of them being missing.

Very similar code exists in libctf and split between elfcpp and gold:
fix both.

(Also sync up elfcpp with a change made to libctf swap.h a few months
ago: since there is no out-of-line definition of the bswap replacements,
they should be declared static inline, not just inline, to prevent the
linker generating out-of-line references to them.)

        PR libctf/25120
libctf/
        * configure.ac: Check for bswap_16, bswap_32, and bswap_64 decls.
        * swap.h (bswap_16): Do not assume that presence of <byteswap.h>
        means this is declared.
        (bswap_32): Likewise.
        (bswap_64): Likewise.
        * configure: Regenerated.
        * config.h.in: Likewise.
gold/
        * configure.ac: Check for bswap_16, bswap_32, and bswap_64 decls.
        * configure: Regenerated.
        * config.h.in: Likewise.
elfcpp/
        * elfcpp_swap.h (bswap_16): Do not assume that presence of
        <byteswap.h> means this is declared.  Make static inline, matching
        recent change to libctf, since there is no non-inline definition
        of these functions.
        (bswap_32): Likewise.
        (bswap_64): Likewise.
---
 elfcpp/ChangeLog     |  10 ++++
 elfcpp/elfcpp_swap.h |  16 ++++--
 gold/ChangeLog       |   7 +++
 gold/config.in       |  12 ++++
 gold/configure       | 127 +++++++++++++++++++++++++++----------------
 gold/configure.ac    |   3 +
 libctf/ChangeLog     |  11 ++++
 libctf/config.h.in   |  12 ++++
 libctf/configure     |  85 ++++++++++++++++++++++++++++-
 libctf/configure.ac  |   3 +
 libctf/swap.h        |  16 +++---
 11 files changed, 241 insertions(+), 61 deletions(-)

diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog
index 3f7e39e6e3..c6dc027b14 100644
--- a/elfcpp/ChangeLog
+++ b/elfcpp/ChangeLog
@@ -1,3 +1,13 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * elfcpp_swap.h (bswap_16): Do not assume that presence of
+ <byteswap.h> means this is declared.  Make static inline, matching
+ recent change to libctf, since there is no non-inline definition
+ of these functions.
+ (bswap_32): Likewise.
+ (bswap_64): Likewise.
+
 2019-09-09  Phil Blundell  <[hidden email]>
 
  binutils 2.33 branch created.
diff --git a/elfcpp/elfcpp_swap.h b/elfcpp/elfcpp_swap.h
index e1f527aec4..24faef5ff8 100644
--- a/elfcpp/elfcpp_swap.h
+++ b/elfcpp/elfcpp_swap.h
@@ -46,15 +46,19 @@
 
 #ifdef HAVE_BYTESWAP_H
 #include <byteswap.h>
-#else
+#endif // defined(HAVE_BYTESWAP_H)
+
 // Provide our own versions of the byteswap functions.
-inline uint16_t
+#if !HAVE_DECL_BSWAP_16
+static inline uint16_t
 bswap_16(uint16_t v)
 {
   return ((v >> 8) & 0xff) | ((v & 0xff) << 8);
 }
+#endif // !HAVE_DECL_BSWAP16
 
-inline uint32_t
+#if !HAVE_DECL_BSWAP_32
+static inline uint32_t
 bswap_32(uint32_t v)
 {
   return (  ((v & 0xff000000) >> 24)
@@ -62,8 +66,10 @@ bswap_32(uint32_t v)
   | ((v & 0x0000ff00) <<  8)
   | ((v & 0x000000ff) << 24));
 }
+#endif // !HAVE_DECL_BSWAP32
 
-inline uint64_t
+#if !HAVE_DECL_BSWAP_64
+static inline uint64_t
 bswap_64(uint64_t v)
 {
   return (  ((v & 0xff00000000000000ULL) >> 56)
@@ -75,7 +81,7 @@ bswap_64(uint64_t v)
   | ((v & 0x000000000000ff00ULL) << 40)
   | ((v & 0x00000000000000ffULL) << 56));
 }
-#endif // !defined(HAVE_BYTESWAP_H)
+#endif // !HAVE_DECL_BSWAP64
 
 // gcc 4.3 and later provides __builtin_bswap32 and __builtin_bswap64.
 
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 3dc2ce81b7..6db168f7df 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * configure.ac: Check for bswap_16, bswap_32, and bswap_64 decls.
+ * configure: Regenerated.
+ * config.h.in: Likewise.
+
 2019-11-26  Martin Liska  <[hidden email]>
 
  * layout.cc (Layout::special_ordering_of_input_section):
diff --git a/gold/config.in b/gold/config.in
index 7bac34aab2..aaad1bee70 100644
--- a/gold/config.in
+++ b/gold/config.in
@@ -52,6 +52,18 @@
    don't. */
 #undef HAVE_DECL_BASENAME
 
+/* Define to 1 if you have the declaration of `bswap_16', and to 0 if you
+   don't. */
+#undef HAVE_DECL_BSWAP_16
+
+/* Define to 1 if you have the declaration of `bswap_32', and to 0 if you
+   don't. */
+#undef HAVE_DECL_BSWAP_32
+
+/* Define to 1 if you have the declaration of `bswap_64', and to 0 if you
+   don't. */
+#undef HAVE_DECL_BSWAP_64
+
 /* Define to 1 if you have the declaration of `ffs', and to 0 if you don't. */
 #undef HAVE_DECL_FFS
 
diff --git a/gold/configure b/gold/configure
index 474c69a125..199a739e7d 100755
--- a/gold/configure
+++ b/gold/configure
@@ -2167,6 +2167,52 @@ fi
 
 } # ac_fn_cxx_check_header_mongrel
 
+# ac_fn_cxx_check_decl LINENO SYMBOL VAR INCLUDES
+# -----------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_cxx_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_cxx_check_decl
+
 # ac_fn_cxx_try_link LINENO
 # -------------------------
 # Try to link conftest.$ac_ext, and return whether this succeeded.
@@ -2279,52 +2325,6 @@ $as_echo "$ac_res" >&6; }
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_cxx_check_func
-
-# ac_fn_cxx_check_decl LINENO SYMBOL VAR INCLUDES
-# -----------------------------------------------
-# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
-# accordingly.
-ac_fn_cxx_check_decl ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  as_decl_name=`echo $2|sed 's/ *(.*//'`
-  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
-$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
-if eval \${$3+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-$4
-int
-main ()
-{
-#ifndef $as_decl_name
-#ifdef __cplusplus
-  (void) $as_decl_use;
-#else
-  (void) $as_decl_name;
-#endif
-#endif
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
-  eval "$3=yes"
-else
-  eval "$3=no"
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-eval ac_res=\$$3
-       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-
-} # ac_fn_cxx_check_decl
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
@@ -9780,6 +9780,41 @@ fi
 done
 
 
+ac_fn_cxx_check_decl "$LINENO" "bswap_16" "ac_cv_have_decl_bswap_16" "#include <byteswap.h>
+"
+if test "x$ac_cv_have_decl_bswap_16" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_BSWAP_16 $ac_have_decl
+_ACEOF
+ac_fn_cxx_check_decl "$LINENO" "bswap_32" "ac_cv_have_decl_bswap_32" "#include <byteswap.h>
+"
+if test "x$ac_cv_have_decl_bswap_32" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_BSWAP_32 $ac_have_decl
+_ACEOF
+ac_fn_cxx_check_decl "$LINENO" "bswap_64" "ac_cv_have_decl_bswap_64" "#include <byteswap.h>
+"
+if test "x$ac_cv_have_decl_bswap_64" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_BSWAP_64 $ac_have_decl
+_ACEOF
+
+
 for ac_header in windows.h
 do :
   ac_fn_cxx_check_header_mongrel "$LINENO" "windows.h" "ac_cv_header_windows_h" "$ac_includes_default"
diff --git a/gold/configure.ac b/gold/configure.ac
index 76db2b7586..13c3c65520 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -602,6 +602,9 @@ AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
 
+dnl Check for bswap_{16,32,64}
+AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
+
 dnl When plugins enabled dynamic loader interface is required. Check headers
 dnl which may provide this interface. Add the necessary library to link.
 AC_CHECK_HEADERS(windows.h)
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 7550015cab..5666eebc60 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,14 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ PR libctf/25120
+ * configure.ac: Check for bswap_16, bswap_32, and bswap_64 decls.
+ * swap.h (bswap_16): Do not assume that presence of <byteswap.h>
+ means this is declared.
+ (bswap_32): Likewise.
+ (bswap_64): Likewise.
+ * configure: Regenerated.
+ * config.h.in: Likewise.
+
 2019-12-16  Nick Alcock  <[hidden email]>
 
  PR libctf/25120
diff --git a/libctf/config.h.in b/libctf/config.h.in
index 4c8be4ab78..e0e37398e0 100644
--- a/libctf/config.h.in
+++ b/libctf/config.h.in
@@ -9,6 +9,18 @@
 /* Define to 1 if you have the <byteswap.h> header file. */
 #undef HAVE_BYTESWAP_H
 
+/* Define to 1 if you have the declaration of `bswap_16', and to 0 if you
+   don't. */
+#undef HAVE_DECL_BSWAP_16
+
+/* Define to 1 if you have the declaration of `bswap_32', and to 0 if you
+   don't. */
+#undef HAVE_DECL_BSWAP_32
+
+/* Define to 1 if you have the declaration of `bswap_64', and to 0 if you
+   don't. */
+#undef HAVE_DECL_BSWAP_64
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
diff --git a/libctf/configure b/libctf/configure
index 66b583fbbe..f56492ca80 100755
--- a/libctf/configure
+++ b/libctf/configure
@@ -1875,6 +1875,52 @@ $as_echo "$ac_res" >&6; }
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_func
+
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
@@ -11385,7 +11431,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11388 "configure"
+#line 11434 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11491,7 +11537,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11494 "configure"
+#line 11540 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12971,6 +13017,41 @@ fi
 done
 
 
+ac_fn_c_check_decl "$LINENO" "bswap_16" "ac_cv_have_decl_bswap_16" "#include <byteswap.h>
+"
+if test "x$ac_cv_have_decl_bswap_16" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_BSWAP_16 $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "bswap_32" "ac_cv_have_decl_bswap_32" "#include <byteswap.h>
+"
+if test "x$ac_cv_have_decl_bswap_32" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_BSWAP_32 $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "bswap_64" "ac_cv_have_decl_bswap_64" "#include <byteswap.h>
+"
+if test "x$ac_cv_have_decl_bswap_64" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_BSWAP_64 $ac_have_decl
+_ACEOF
+
+
 
 
 
diff --git a/libctf/configure.ac b/libctf/configure.ac
index aa40e4e234..ffd1f0edac 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -99,6 +99,9 @@ AC_C_BIGENDIAN
 AC_CHECK_HEADERS(byteswap.h endian.h)
 AC_CHECK_FUNCS(pread)
 
+dnl Check for bswap_{16,32,64}
+AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
+
 dnl Check for qsort_r.  (Taken from gnulib.)
 AC_CHECK_FUNCS_ONCE([qsort_r])
 if test $ac_cv_func_qsort_r = yes; then
diff --git a/libctf/swap.h b/libctf/swap.h
index ac62ac78d1..63435b8d92 100644
--- a/libctf/swap.h
+++ b/libctf/swap.h
@@ -25,15 +25,19 @@
 
 #ifdef HAVE_BYTESWAP_H
 #include <byteswap.h>
-#else
+#endif /* defined(HAVE_BYTESWAP_H) */
 
 /* Provide our own versions of the byteswap functions.  */
+
+#if !HAVE_DECL_BSWAP_16
 static inline uint16_t
 bswap_16 (uint16_t v)
 {
   return ((v >> 8) & 0xff) | ((v & 0xff) << 8);
 }
+#endif /* !HAVE_DECL_BSWAP16 */
 
+#if !HAVE_DECL_BSWAP_32
 static inline uint32_t
 bswap_32 (uint32_t v)
 {
@@ -42,13 +46,9 @@ bswap_32 (uint32_t v)
   | ((v & 0x0000ff00) <<  8)
   | ((v & 0x000000ff) << 24));
 }
+#endif /* !HAVE_DECL_BSWAP32 */
 
-inline uint64_t
-bswap_identity_64 (uint64_t v)
-{
-  return v;
-}
-
+#if !HAVE_DECL_BSWAP_64
 static inline uint64_t
 bswap_64 (uint64_t v)
 {
@@ -61,6 +61,6 @@ bswap_64 (uint64_t v)
   | ((v & 0x000000000000ff00ULL) << 40)
   | ((v & 0x00000000000000ffULL) << 56));
 }
-#endif /* !defined(HAVE_BYTESWAP_H) */
+#endif /* !HAVE_DECL_BSWAP64 */
 
 #endif /* !defined(_CTF_SWAP_H) */
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 10/11] libctf: add some missing #includes.

Nick Alcock
In reply to this post by Nick Alcock
Causes warnings on (at least) recent FreeBSD.

libctf/
        * ctf-create.c: Include <unistd.h>.
        * ctf-open-bfd.c: Likewise.
---
 libctf/ChangeLog      | 5 +++++
 libctf/ctf-create.c   | 1 +
 libctf/ctf-open-bfd.c | 1 +
 3 files changed, 7 insertions(+)

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 5666eebc60..f172cbf864 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ * ctf-create.c: Include <unistd.h>.
+ * ctf-open-bfd.c: Likewise.
+
 2019-12-16  Nick Alcock  <[hidden email]>
 
  PR libctf/25120
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index a63c213d33..b875075f50 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -21,6 +21,7 @@
 #include <sys/param.h>
 #include <assert.h>
 #include <string.h>
+#include <unistd.h>
 #include <zlib.h>
 
 #ifndef roundup
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
index b40d3778d0..3264fc9a3e 100644
--- a/libctf/ctf-open-bfd.c
+++ b/libctf/ctf-open-bfd.c
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <string.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include <elf.h>
 #include <bfd.h>
 #include "swap.h"
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

[PATCH 11/11] libctf: support platforms with separate libintl

Nick Alcock
In reply to this post by Nick Alcock
We were not using the right configure machinery to spot libintl on
platforms where it was required, leading to the spurious failure of
various configure tests (e.g. for things like ELF support in BFD).

libctf/
        * aclocal.m4: Add config/gettext-sister.m4: Shuffle into
        alphabetical order.
        * configure.ac: Add ZW_GNU_GETTEXT_SISTER_DIR.
        * config.h.in: Regenerated.
        * Makefile.in: Likewise.
        * configure: Likewise.
---
 libctf/ChangeLog    |  9 +++++
 libctf/Makefile.in  | 19 ++++++++--
 libctf/aclocal.m4   |  3 +-
 libctf/config.h.in  |  4 +++
 libctf/configure    | 86 +++++++++++++++++++++++++++++++++++++++++++--
 libctf/configure.ac |  1 +
 6 files changed, 116 insertions(+), 6 deletions(-)

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index f172cbf864..45616c29ae 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,12 @@
+2019-12-16  Nick Alcock  <[hidden email]>
+
+ * aclocal.m4: Add config/gettext-sister.m4: Shuffle into
+ alphabetical order.
+ * configure.ac: Add ZW_GNU_GETTEXT_SISTER_DIR.
+ * config.h.in: Regenerated.
+ * Makefile.in: Likewise.
+ * configure: Likewise.
+
 2019-12-16  Nick Alcock  <[hidden email]>
 
  * ctf-create.c: Include <unistd.h>.
diff --git a/libctf/Makefile.in b/libctf/Makefile.in
index d6e73cac73..1ebf9f9c7c 100644
--- a/libctf/Makefile.in
+++ b/libctf/Makefile.in
@@ -110,13 +110,14 @@ host_triplet = @host@
 @NEED_CTF_QSORT_R_TRUE@am__append_1 = ctf-qsort_r.c
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
+ $(top_srcdir)/../config/acx.m4 \
  $(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/gettext-sister.m4 \
  $(top_srcdir)/../config/lead-dot.m4 \
  $(top_srcdir)/../config/override.m4 \
  $(top_srcdir)/../config/warnings.m4 \
- $(top_srcdir)/../config/zlib.m4 \
- $(top_srcdir)/../bfd/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../config/zlib.m4 $(top_srcdir)/../libtool.m4 \
  $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
  $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
  $(top_srcdir)/configure.ac
@@ -297,12 +298,15 @@ AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
 BFD_DEPENDENCIES = @BFD_DEPENDENCIES@
 BFD_LIBADD = @BFD_LIBADD@
+CATALOGS = @CATALOGS@
+CATOBJEXT = @CATOBJEXT@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CYGPATH_W = @CYGPATH_W@
+DATADIRNAME = @DATADIRNAME@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
 DSYMUTIL = @DSYMUTIL@
@@ -313,14 +317,20 @@ ECHO_T = @ECHO_T@
 EGREP = @EGREP@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
+GENCAT = @GENCAT@
+GMSGFMT = @GMSGFMT@
 GREP = @GREP@
+INCINTL = @INCINTL@
 INSTALL = @INSTALL@
 INSTALL_DATA = @INSTALL_DATA@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INSTOBJEXT = @INSTOBJEXT@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBINTL = @LIBINTL@
+LIBINTL_DEP = @LIBINTL_DEP@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -344,6 +354,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
 PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
+POSUB = @POSUB@
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
@@ -351,10 +362,12 @@ SHARED_LDFLAGS = @SHARED_LDFLAGS@
 SHARED_LIBADD = @SHARED_LIBADD@
 SHELL = @SHELL@
 STRIP = @STRIP@
+USE_NLS = @USE_NLS@
 VERSION = @VERSION@
 VERSION_FLAGS = @VERSION_FLAGS@
 WARN_PEDANTIC = @WARN_PEDANTIC@
 WERROR = @WERROR@
+XGETTEXT = @XGETTEXT@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
diff --git a/libctf/aclocal.m4 b/libctf/aclocal.m4
index 04583b42f0..8ae4b53462 100644
--- a/libctf/aclocal.m4
+++ b/libctf/aclocal.m4
@@ -1227,13 +1227,14 @@ AC_SUBST([am__tar])
 AC_SUBST([am__untar])
 ]) # _AM_PROG_TAR
 
+m4_include([../bfd/acinclude.m4])
 m4_include([../config/acx.m4])
 m4_include([../config/depstand.m4])
+m4_include([../config/gettext-sister.m4])
 m4_include([../config/lead-dot.m4])
 m4_include([../config/override.m4])
 m4_include([../config/warnings.m4])
 m4_include([../config/zlib.m4])
-m4_include([../bfd/acinclude.m4])
 m4_include([../libtool.m4])
 m4_include([../ltoptions.m4])
 m4_include([../ltsugar.m4])
diff --git a/libctf/config.h.in b/libctf/config.h.in
index e0e37398e0..95f08a9e3b 100644
--- a/libctf/config.h.in
+++ b/libctf/config.h.in
@@ -3,6 +3,10 @@
 /* Define if building universal (internal helper macro) */
 #undef AC_APPLE_UNIVERSAL_BUILD
 
+/* Define to 1 if translation of program messages to the user's native
+   language is requested. */
+#undef ENABLE_NLS
+
 /* Whether libbfd was configured for an ELF target. */
 #undef HAVE_BFD_ELF
 
diff --git a/libctf/configure b/libctf/configure
index f56492ca80..71fcda3688 100755
--- a/libctf/configure
+++ b/libctf/configure
@@ -680,6 +680,18 @@ build_vendor
 build_cpu
 build
 LIBTOOL
+CATOBJEXT
+GENCAT
+INSTOBJEXT
+DATADIRNAME
+CATALOGS
+POSUB
+GMSGFMT
+XGETTEXT
+INCINTL
+LIBINTL_DEP
+LIBINTL
+USE_NLS
 ac_ct_AR
 AR
 RANLIB
@@ -5283,6 +5295,76 @@ unknown)
   ;;
 esac
 
+# If we haven't got the data from the intl directory,
+# assume NLS is disabled.
+USE_NLS=no
+LIBINTL=
+LIBINTL_DEP=
+INCINTL=
+XGETTEXT=
+GMSGFMT=
+POSUB=
+
+if test -f  ../intl/config.intl; then
+  .  ../intl/config.intl
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether NLS is requested" >&5
+$as_echo_n "checking whether NLS is requested... " >&6; }
+if test x"$USE_NLS" != xyes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+$as_echo "#define ENABLE_NLS 1" >>confdefs.h
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for catalogs to be installed" >&5
+$as_echo_n "checking for catalogs to be installed... " >&6; }
+  # Look for .po and .gmo files in the source directory.
+  CATALOGS=
+  XLINGUAS=
+  for cat in $srcdir/po/*.gmo $srcdir/po/*.po; do
+    # If there aren't any .gmo files the shell will give us the
+    # literal string "../path/to/srcdir/po/*.gmo" which has to be
+    # weeded out.
+    case "$cat" in *\**)
+      continue;;
+    esac
+    # The quadruple backslash is collapsed to a double backslash
+    # by the backticks, then collapsed again by the double quotes,
+    # leaving us with one backslash in the sed expression (right
+    # before the dot that mustn't act as a wildcard).
+    cat=`echo $cat | sed -e "s!$srcdir/po/!!" -e "s!\\\\.po!.gmo!"`
+    lang=`echo $cat | sed -e "s!\\\\.gmo!!"`
+    # The user is allowed to set LINGUAS to a list of languages to
+    # install catalogs for.  If it's empty that means "all of them."
+    if test "x$LINGUAS" = x; then
+      CATALOGS="$CATALOGS $cat"
+      XLINGUAS="$XLINGUAS $lang"
+    else
+      case "$LINGUAS" in *$lang*)
+        CATALOGS="$CATALOGS $cat"
+        XLINGUAS="$XLINGUAS $lang"
+        ;;
+      esac
+    fi
+  done
+  LINGUAS="$XLINGUAS"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LINGUAS" >&5
+$as_echo "$LINGUAS" >&6; }
+
+
+    DATADIRNAME=share
+
+  INSTOBJEXT=.mo
+
+  GENCAT=gencat
+
+  CATOBJEXT=.gmo
+
+fi
 
 # Check whether --enable-shared was given.
 if test "${enable_shared+set}" = set; then :
@@ -11431,7 +11513,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11434 "configure"
+#line 11516 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11537,7 +11619,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11540 "configure"
+#line 11622 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/libctf/configure.ac b/libctf/configure.ac
index ffd1f0edac..cc7701515c 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -31,6 +31,7 @@ AC_PROG_MAKE_SET
 AC_PROG_CC
 AC_PROG_RANLIB
 AM_PROG_AR
+ZW_GNU_GETTEXT_SISTER_DIR
 
 dnl Default to a non shared library.  This may be overridden by the
 dnl configure option --enable-shared.
--
2.24.1.242.gb57e918ca5

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 00/11] libctf: various portability fixes and small bugfixes

Alan Modra-3
In reply to this post by Nick Alcock
On Mon, Dec 16, 2019 at 10:53:46PM +0000, Nick Alcock wrote:
> The libiberty and binutils bits outside the first patch in the series have not
> appeared here before and need review.

The binutils part is fine.  libiberty patches should go to
[hidden email] as per libiberty/README.  You probably should
post just the libiberty part of the patch, making it clear in the
subject that it is a libiberty patch and cc the libiberty maintainer.
binutils/libiberty can be imported from the gcc repo later by anyone
with write access to the binutils repo.  If the gcc patch approval
process takes too long then you may apply the patch to binutils.

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 00/11] libctf: various portability fixes and small bugfixes

Nick Alcock
On 19 Dec 2019, Alan Modra outgrape:

> On Mon, Dec 16, 2019 at 10:53:46PM +0000, Nick Alcock wrote:
>> The libiberty and binutils bits outside the first patch in the series have not
>> appeared here before and need review.
>
> The binutils part is fine.  libiberty patches should go to
> [hidden email] as per libiberty/README.

Oh, thank you, I never noticed this before. I'll split out the
libiberty/include portion and respin things as suggested there (make
maint-deps and make-stamp-functions, etc.)

> binutils/libiberty can be imported from the gcc repo later by anyone
> with write access to the binutils repo.  If the gcc patch approval
> process takes too long then you may apply the patch to binutils.

I guess this means I have to respin this bit against GCC trunk (and keep
the current patch as a necessary-for-testing-but-will-be-dropped
portion if the resulting patch is any different).