public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] libctf: small fixes
@ 2021-06-25 16:12 Nick Alcock
  2021-06-25 16:12 ` [PATCH 1/3] libctf: link against libiberty before linking in libbfd or libctf-nobfd Nick Alcock
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nick Alcock @ 2021-06-25 16:12 UTC (permalink / raw)
  To: binutils

This patch series is small stuff confined to libctf/ and not needing
review: problems with the relink at install time picking up the wrong
libbfd (PR libctf/27360), problems with backward-compatibility code to
handle symtypetab sections emitted by obsolete pre-upstreaming
CTF-capable GCCs; and some warnings causing spurious test failures on
some platforms.

No review needed unless people really want to.

Nick Alcock (3):
  libctf: link against libiberty before linking in libbfd or
    libctf-nobfd
  libctf: fix handling of CTF symtypetab sections emitted by older GCC
  libctf, testsuite: fix various warnings in tests

 libctf/Makefile.am                                         | 6 +++++-
 libctf/Makefile.in                                         | 7 ++++++-
 libctf/ctf-open.c                                          | 7 ++++---
 libctf/testsuite/libctf-lookup/conflicting-type-syms.c     | 3 ---
 libctf/testsuite/libctf-lookup/enum-symbol.c               | 3 ---
 .../libctf-regression/nonstatic-var-section-ld-r.c         | 4 ++--
 .../testsuite/libctf-regression/nonstatic-var-section-ld.c | 4 ++--
 .../libctf-regression/nonstatic-var-section-ld.lk          | 2 +-
 libctf/testsuite/libctf-regression/pptrtab.c               | 1 -
 .../testsuite/libctf-regression/type-add-unnamed-struct.c  | 2 --
 libctf/testsuite/libctf-writable/pptrtab.c                 | 2 +-
 .../libctf-writable/reserialize-strtab-corruption.c        | 1 -
 .../libctf-writable/symtypetab-nonlinker-writeout.c        | 6 ++++--
 13 files changed, 25 insertions(+), 23 deletions(-)

-- 
2.32.0.255.gd9b1d14a2a


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] libctf: link against libiberty before linking in libbfd or libctf-nobfd
  2021-06-25 16:12 [PATCH 0/3] libctf: small fixes Nick Alcock
@ 2021-06-25 16:12 ` Nick Alcock
  2021-06-25 16:12 ` [PATCH 2/3] libctf: fix handling of CTF symtypetab sections emitted by older GCC Nick Alcock
  2021-06-25 16:12 ` [PATCH 3/3] libctf, testsuite: fix various warnings in tests Nick Alcock
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Alcock @ 2021-06-25 16:12 UTC (permalink / raw)
  To: binutils

This ensures that the CTF_LIBADD, which always contains at least this
when doing a shared link:

-L`pwd`/../libiberty/pic -liberty

appears in the link line before any requirements pulled in by libbfd.la,
which include -liberty but because it is install-time do not include the
-L`pwd`/../libiberty/pic portion (in an indirect dep like this, the path
comes from the libbfd.la file, and is an install path).  libiberty also
appears after libbfd in the link line by virtue of libctf-nobfd.la,
because libctf-nobfd has to follow libbfd in the link line, and that
needs symbols from libiberty too.

Without this, an installed liberty might well be pulled in by libbfd,
and if --enable-install-libiberty is not specified this libiberty might
be completely incompatible with what is being installed and break either
or boht of libbfd and libctf. (The specific problem observed here is
that bsearch_r was not present, but other problems might easily be
observed in future too.)

Because ld links against libctf, this has a tendency to break the system
linker at install time too, if installing with --prefix=/usr.  That's
quite unpleasant to recover from.

libctf/ChangeLog
2021-06-12  Nick Alcock  <nick.alcock@oracle.com>

	PR libctf/27360
	* Makefile.am (libctf_la_LIBADD): Link against libiberty
	before pulling in libbfd.la or pulling in libctf-nobfd.la.
	* Makefile.in: Regenerate.
---
 libctf/Makefile.am | 6 +++++-
 libctf/Makefile.in | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libctf/Makefile.am b/libctf/Makefile.am
index e586d25fb37..308daa9a03c 100644
--- a/libctf/Makefile.am
+++ b/libctf/Makefile.am
@@ -52,7 +52,11 @@ if NEED_CTF_QSORT_R
 libctf_nobfd_la_SOURCES += ctf-qsort_r.c
 endif
 
-libctf_la_LIBADD = ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
+# @CTF_LIBADD@ appears here twice: once, to force libiberty to get searched before
+# install-time libbfd adds a -L to the install dir (possibly pointing at an
+# incompatible libiberty), and once via lictf_nobfd_la_LIBADD so that the
+# references in there get picked up.
+libctf_la_LIBADD =  @CTF_LIBADD@ ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
 libctf_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=0
 libctf_la_LDFLAGS = $(libctf_nobfd_la_LDFLAGS)
 libctf_la_SOURCES = $(libctf_nobfd_la_SOURCES) ctf-open-bfd.c
diff --git a/libctf/Makefile.in b/libctf/Makefile.in
index 5cfa100f9cc..b594a3e1362 100644
--- a/libctf/Makefile.in
+++ b/libctf/Makefile.in
@@ -476,7 +476,12 @@ libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 	ctf-decl.c ctf-error.c ctf-hash.c ctf-labels.c ctf-dedup.c \
 	ctf-link.c ctf-lookup.c ctf-open.c ctf-serialize.c ctf-sha1.c \
 	ctf-string.c ctf-subr.c ctf-types.c ctf-util.c $(am__append_1)
-libctf_la_LIBADD = ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
+
+# @CTF_LIBADD@ appears here twice: once, to force libiberty to get searched before
+# install-time libbfd adds a -L to the install dir (possibly pointing at an
+# incompatible libiberty), and once via lictf_nobfd_la_LIBADD so that the
+# references in there get picked up.
+libctf_la_LIBADD = @CTF_LIBADD@ ../bfd/libbfd.la $(libctf_nobfd_la_LIBADD)
 libctf_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=0
 libctf_la_LDFLAGS = $(libctf_nobfd_la_LDFLAGS)
 libctf_la_SOURCES = $(libctf_nobfd_la_SOURCES) ctf-open-bfd.c
-- 
2.32.0.255.gd9b1d14a2a


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] libctf: fix handling of CTF symtypetab sections emitted by older GCC
  2021-06-25 16:12 [PATCH 0/3] libctf: small fixes Nick Alcock
  2021-06-25 16:12 ` [PATCH 1/3] libctf: link against libiberty before linking in libbfd or libctf-nobfd Nick Alcock
@ 2021-06-25 16:12 ` Nick Alcock
  2021-06-25 16:12 ` [PATCH 3/3] libctf, testsuite: fix various warnings in tests Nick Alcock
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Alcock @ 2021-06-25 16:12 UTC (permalink / raw)
  To: binutils

Older (pre-upstreaming) GCC emits a function symtypetab section of a
format never read by any extant libctf.  We can detect such CTF dicts by
the lack of the CTF_F_NEWFUNCINFO flag in their header, and we do so
when reading in the symtypetab section -- but if the set of symbols with
types is sufficiently sparse, even an older GCC will emit a function
index section.

In NEWFUNCINFO-capable compilers, this section will always be the exact
same length as the corresponding function section (each is an array of
uint32_t, associated 1:1 with each other). But this is not true for the
older compiler, for which the sections are different lengths.  We check
to see if the function symtypetab section and its index are the same
length, but we fail to skip this check when this is not a NEWFUNCINFO
dict, and emit a spurious corruption error for a CTF dict we could
have perfectly well opened and used.

Fix trivial: check the flag (and fix the terrible grammar of the error
message at the same time).

libctf/ChangeLog
2021-06-16  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-open.c (ctf_bufopen_internal): Don't complain about corrupt
	function index symtypetab sections if this is an old-format
	function symtypetab section (which should be ignored in any case).
	Fix bad grammar.
---
 libctf/ctf-open.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 1c69dc83102..2a4cbf84acd 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -1449,7 +1449,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
        != hp->cth_funcoff - hp->cth_objtoff))
     {
       ctf_err_warn (NULL, 0, ECTF_CORRUPT,
-		    _("Object index section exists is neither empty nor the "
+		    _("Object index section is neither empty nor the "
 		      "same length as the object section: %u versus %u "
 		      "bytes"), hp->cth_funcoff - hp->cth_objtoff,
 		    hp->cth_funcidxoff - hp->cth_objtidxoff);
@@ -1458,10 +1458,11 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
 
   if ((hp->cth_varoff - hp->cth_funcidxoff != 0) &&
       (hp->cth_varoff - hp->cth_funcidxoff
-       != hp->cth_objtidxoff - hp->cth_funcoff))
+       != hp->cth_objtidxoff - hp->cth_funcoff) &&
+      (hp->cth_flags & CTF_F_NEWFUNCINFO))
     {
       ctf_err_warn (NULL, 0, ECTF_CORRUPT,
-		    _("Function index section exists is neither empty nor the "
+		    _("Function index section is neither empty nor the "
 		      "same length as the function section: %u versus %u "
 		      "bytes"), hp->cth_objtidxoff - hp->cth_funcoff,
 		    hp->cth_varoff - hp->cth_funcidxoff);
-- 
2.32.0.255.gd9b1d14a2a


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] libctf, testsuite: fix various warnings in tests
  2021-06-25 16:12 [PATCH 0/3] libctf: small fixes Nick Alcock
  2021-06-25 16:12 ` [PATCH 1/3] libctf: link against libiberty before linking in libbfd or libctf-nobfd Nick Alcock
  2021-06-25 16:12 ` [PATCH 2/3] libctf: fix handling of CTF symtypetab sections emitted by older GCC Nick Alcock
@ 2021-06-25 16:12 ` Nick Alcock
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Alcock @ 2021-06-25 16:12 UTC (permalink / raw)
  To: binutils

These warnings are all off by default, but if they do fire you get
spurious ERRORs when running make check-libctf.

libctf/ChangeLog
2021-06-16  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/libctf-lookup/enum-symbol.c: Remove unused label.
	* testsuite/libctf-lookup/conflicting-type-syms.c: Remove unused
	variables.
	* testsuite/libctf-regression/pptrtab.c: Likewise.
	* testsuite/libctf-regression/type-add-unnamed-struct.c: Likewise.
	* testsuite/libctf-writable/pptrtab.c: Likewise.
	* testsuite/libctf-writable/reserialize-strtab-corruption.c:
	Likewise.
	* testsuite/libctf-regression/nonstatic-var-section-ld-r.c: Fix
	format string.
	* testsuite/libctf-regression/nonstatic-var-section-ld.c:
	Likewise.
	* testsuite/libctf-regression/nonstatic-var-section-ld.lk: Adjust.
	* testsuite/libctf-writable/symtypetab-nonlinker-writeout.c: Fix
	initializer.
---
 libctf/testsuite/libctf-lookup/conflicting-type-syms.c      | 3 ---
 libctf/testsuite/libctf-lookup/enum-symbol.c                | 3 ---
 .../libctf-regression/nonstatic-var-section-ld-r.c          | 4 ++--
 .../testsuite/libctf-regression/nonstatic-var-section-ld.c  | 4 ++--
 .../testsuite/libctf-regression/nonstatic-var-section-ld.lk | 2 +-
 libctf/testsuite/libctf-regression/pptrtab.c                | 1 -
 .../testsuite/libctf-regression/type-add-unnamed-struct.c   | 2 --
 libctf/testsuite/libctf-writable/pptrtab.c                  | 2 +-
 .../libctf-writable/reserialize-strtab-corruption.c         | 1 -
 .../libctf-writable/symtypetab-nonlinker-writeout.c         | 6 ++++--
 10 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/libctf/testsuite/libctf-lookup/conflicting-type-syms.c b/libctf/testsuite/libctf-lookup/conflicting-type-syms.c
index ffe6983e250..239b8775964 100644
--- a/libctf/testsuite/libctf-lookup/conflicting-type-syms.c
+++ b/libctf/testsuite/libctf-lookup/conflicting-type-syms.c
@@ -12,9 +12,6 @@ main (int argc, char *argv[])
   int err;
   ctf_id_t a, b, ignore1, ignore2, tmp;
   char *foo;
-  ctf_next_t *i = NULL;
-  const char *name;
-  int val;
 
   if (argc != 2)
     {
diff --git a/libctf/testsuite/libctf-lookup/enum-symbol.c b/libctf/testsuite/libctf-lookup/enum-symbol.c
index c67478fe780..1244c900434 100644
--- a/libctf/testsuite/libctf-lookup/enum-symbol.c
+++ b/libctf/testsuite/libctf-lookup/enum-symbol.c
@@ -57,9 +57,6 @@ main (int argc, char *argv[])
   fprintf (stderr, "%s: Symbol re-lookup error (caching bug): %s\n", argv[0],
 	   ctf_errmsg (err));
   return 1;
- err:
-  fprintf (stderr, "Lookup failed: %s\n", ctf_errmsg (ctf_errno (fp)));
-  return 1;
  nerr:
   fprintf (stderr, "iteration failed: %s\n", ctf_errmsg (ctf_errno (fp)));
   return 1;
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c
index 2fa761a1d03..6ae2ea53042 100644
--- a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c
@@ -31,12 +31,12 @@ main (int argc, char *argv[])
      ld -r link.  */
 
   if ((foo_type = ctf_lookup_variable (fp, "foo")) == CTF_ERR)
-    printf ("Cannot look up foo\n", ctf_errmsg (ctf_errno (fp)));
+    printf ("Cannot look up foo: %s\n", ctf_errmsg (ctf_errno (fp)));
   else
     printf ("foo is of type %lx\n", foo_type);
 
   if ((bar_type = ctf_lookup_variable (fp, "bar")) == CTF_ERR)
-    printf ("Cannot look up bar\n", ctf_errmsg (ctf_errno (fp)));
+    printf ("Cannot look up bar: %s\n", ctf_errmsg (ctf_errno (fp)));
   else
     printf ("bar is of type %lx\n", bar_type);
 
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c
index 4e3a74842b2..93988eb1e8d 100644
--- a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c
@@ -30,12 +30,12 @@ main (int argc, char *argv[])
      should have been erased.  */
 
   if ((foo_type = ctf_lookup_variable (fp, "foo")) == CTF_ERR)
-    printf ("Cannot look up foo\n", ctf_errmsg (ctf_errno (fp)));
+    printf ("Cannot look up foo: %s\n", ctf_errmsg (ctf_errno (fp)));
   else
     printf ("foo is of type %lx\n", foo_type);
 
   if ((bar_type = ctf_lookup_variable (fp, "bar")) == CTF_ERR)
-    printf ("Cannot look up bar\n", ctf_errmsg (ctf_errno (fp)));
+    printf ("Cannot look up bar: %s\n", ctf_errmsg (ctf_errno (fp)));
   else
     printf ("bar is of type %lx\n", bar_type);
 
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk
index edb397a333a..2ea4d323bfc 100644
--- a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk
@@ -2,5 +2,5 @@
 # link: on
 # link_flags: -Wl,--ctf-variables
 foo is of type [0-9a-f]*
-Cannot look up bar
+Cannot look up bar: No type information available for symbol.
 foo missing from the data object section
diff --git a/libctf/testsuite/libctf-regression/pptrtab.c b/libctf/testsuite/libctf-regression/pptrtab.c
index fe1b8fe2b43..2ef5f9c5cc0 100644
--- a/libctf/testsuite/libctf-regression/pptrtab.c
+++ b/libctf/testsuite/libctf-regression/pptrtab.c
@@ -10,7 +10,6 @@ main (int argc, char *argv[])
   ctf_next_t *i = NULL;
   ctf_id_t type;
   const char *arcname;
-  char *type_name;
   int err;
 
   if (argc != 2)
diff --git a/libctf/testsuite/libctf-regression/type-add-unnamed-struct.c b/libctf/testsuite/libctf-regression/type-add-unnamed-struct.c
index 16ff0948b17..cf10804814c 100644
--- a/libctf/testsuite/libctf-regression/type-add-unnamed-struct.c
+++ b/libctf/testsuite/libctf-regression/type-add-unnamed-struct.c
@@ -8,10 +8,8 @@ main (int argc, char *argv[])
   ctf_dict_t *fp;
   ctf_archive_t *ctf;
   ctf_dict_t *dyn;
-  ctf_next_t *i = NULL;
   ctf_id_t type;
   ctf_id_t newtype;
-  const char *memb;
   ctf_membinfo_t mi;
   const char *membs[] = { "bar", "baz", "foo", NULL };
   const char **walk;
diff --git a/libctf/testsuite/libctf-writable/pptrtab.c b/libctf/testsuite/libctf-writable/pptrtab.c
index 68c356352d7..b8d1e63b997 100644
--- a/libctf/testsuite/libctf-writable/pptrtab.c
+++ b/libctf/testsuite/libctf-writable/pptrtab.c
@@ -7,7 +7,7 @@ main (int argc, char *argv[])
 {
   ctf_dict_t *pfp;
   ctf_dict_t *cfp;
-  ctf_id_t base, base2, ptr, ptr2, type, last_type;
+  ctf_id_t base, base2, ptr, type, last_type;
   ctf_encoding_t encoding = { CTF_INT_SIGNED, 0, sizeof (int) };
   ctf_encoding_t encoding2 = { CTF_INT_SIGNED, 0, sizeof (long) };
   char *type_name;
diff --git a/libctf/testsuite/libctf-writable/reserialize-strtab-corruption.c b/libctf/testsuite/libctf-writable/reserialize-strtab-corruption.c
index 1593325da77..2c9ec8d9ed2 100644
--- a/libctf/testsuite/libctf-writable/reserialize-strtab-corruption.c
+++ b/libctf/testsuite/libctf-writable/reserialize-strtab-corruption.c
@@ -13,7 +13,6 @@ main (int argc, char *argv[])
   ctf_snapshot_id_t snap;
   unsigned char *foo;
   size_t foo_size;
-  const char *bar;
   int err;
   char name[64];
 
diff --git a/libctf/testsuite/libctf-writable/symtypetab-nonlinker-writeout.c b/libctf/testsuite/libctf-writable/symtypetab-nonlinker-writeout.c
index bdc3faa944c..7a2b88d6dfa 100644
--- a/libctf/testsuite/libctf-writable/symtypetab-nonlinker-writeout.c
+++ b/libctf/testsuite/libctf-writable/symtypetab-nonlinker-writeout.c
@@ -174,10 +174,12 @@ try_maybe_reporting (int report)
   } *expected;
   struct ctf_symtype_expected expected_obj[] = { { "data_a", base2 },
 						 { "data_b", base3 },
-						 { "data_c", base }, NULL };
+						 { "data_c", base },
+						 { NULL, 0 } };
   struct ctf_symtype_expected expected_func[] = { { "func_a", func2 },
 						  { "func_b", func3 },
-						  { "func_c", func }, NULL };
+						  { "func_c", func },
+						  { NULL, 0 } };
   expected = expected_obj;
 
   while ((symtype = ctf_symbol_next (fp, &i, &symname, 0)) != CTF_ERR)
-- 
2.32.0.255.gd9b1d14a2a


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-25 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 16:12 [PATCH 0/3] libctf: small fixes Nick Alcock
2021-06-25 16:12 ` [PATCH 1/3] libctf: link against libiberty before linking in libbfd or libctf-nobfd Nick Alcock
2021-06-25 16:12 ` [PATCH 2/3] libctf: fix handling of CTF symtypetab sections emitted by older GCC Nick Alcock
2021-06-25 16:12 ` [PATCH 3/3] libctf, testsuite: fix various warnings in tests Nick Alcock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).