public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Alcock <nick.alcock@oracle.com>
To: binutils@sourceware.org
Subject: [PATCH 4/4] libctf, ld: handle nonrepresentable types better
Date: Mon, 11 Oct 2021 20:18:10 +0100	[thread overview]
Message-ID: <20211011191810.274535-4-nick.alcock@oracle.com> (raw)
In-Reply-To: <20211011191810.274535-1-nick.alcock@oracle.com>

ctf_type_visit (used, among other things, by the type dumping code) was
aborting when it saw a nonrepresentable type anywhere: even a single
structure member with a nonrepresentable type caused an abort with
ECTF_NONREPRESENTABLE.  This is not useful behaviour, given that the
abort comes from a type-resolution we are only doing in order to
determine whether the type is a structure or union.  We know
nonrepresentable types can't be either, so handle that case and
pass the nonrepresentable type down.

(The added test verifies that the dumper now handles this case and
prints nonrepresentable structure members as it already does
nonrepresentable top-level types, rather than skipping the whole
structure -- or, without the previous commit, skipping the whole types
section.)

ld/ChangeLog
2021-10-08  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/nonrepresentable-member.*: New test.

libctf/ChangeLog
2021-10-08  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-types.c (ctf_type_rvisit): Handle nonrepresentable types.
---
 ld/testsuite/ld-ctf/nonrepresentable-member.c |  7 ++++++
 ld/testsuite/ld-ctf/nonrepresentable-member.d | 25 +++++++++++++++++++
 libctf/ctf-types.c                            | 19 +++++++++-----
 3 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 ld/testsuite/ld-ctf/nonrepresentable-member.c
 create mode 100644 ld/testsuite/ld-ctf/nonrepresentable-member.d

diff --git a/ld/testsuite/ld-ctf/nonrepresentable-member.c b/ld/testsuite/ld-ctf/nonrepresentable-member.c
new file mode 100644
index 00000000000..b3657af01e1
--- /dev/null
+++ b/ld/testsuite/ld-ctf/nonrepresentable-member.c
@@ -0,0 +1,7 @@
+struct blah
+{
+  int boring;
+  int __attribute__((vector_size(8))) foo;
+  const int __attribute__((vector_size(8))) bar;
+  int this_is_printed;
+} wibble __attribute__((__used__));
diff --git a/ld/testsuite/ld-ctf/nonrepresentable-member.d b/ld/testsuite/ld-ctf/nonrepresentable-member.d
new file mode 100644
index 00000000000..6c76253a8c1
--- /dev/null
+++ b/ld/testsuite/ld-ctf/nonrepresentable-member.d
@@ -0,0 +1,25 @@
+#as:
+#source: nonrepresentable-member.c
+#objdump: --ctf
+#ld: -shared
+#name: Nonrepresentable members
+
+.*: +file format .*
+
+Contents of CTF section .ctf:
+
+  Header:
+    Magic number: 0xdff2
+    Version: 4 \(CTF_VERSION_3\)
+#...
+  Types:
+#...
+    0x[0-9a-f]*: \(kind 6\) struct blah .*
+        *\[0x0\] boring: ID 0x[0-9a-f]*: \(kind 1\) int .*
+        *\[0x[0-9a-f]*\] foo: .* \(.*represent.*\)
+        *\[0x[0-9a-f]*\] bar: .* \(.*represent.*\)
+        *\[0x[0-9a-f]*\] this_is_printed: ID 0x[0-9a-f]*: \(kind 1\) int .*
+#...
+
+  Strings:
+#...
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index 243de9348d3..55834856da9 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -1641,20 +1641,27 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func,
   unsigned char *vlen;
   ssize_t size, increment, vbytes;
   uint32_t kind, n, i = 0;
+  int nonrepresentable = 0;
   int rc;
 
-  if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
-    return -1;			/* errno is set for us.  */
+  if ((type = ctf_type_resolve (fp, type)) == CTF_ERR) {
+    if (ctf_errno (fp) != ECTF_NONREPRESENTABLE)
+      return -1;		/* errno is set for us.  */
+    else
+      nonrepresentable = 1;
+  }
 
-  if ((tp = ctf_lookup_by_id (&fp, type)) == NULL)
-    return -1;			/* errno is set for us.  */
+  if (!nonrepresentable)
+    if ((tp = ctf_lookup_by_id (&fp, type)) == NULL)
+      return -1;		/* errno is set for us.  */
 
   if ((rc = func (name, otype, offset, depth, arg)) != 0)
     return rc;
 
-  kind = LCTF_INFO_KIND (fp, tp->ctt_info);
+  if (!nonrepresentable)
+    kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
-  if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
+  if (nonrepresentable || (kind != CTF_K_STRUCT && kind != CTF_K_UNION))
     return 0;
 
   ctf_get_ctt_size (fp, tp, &size, &increment);
-- 
2.33.0.256.gb827f06fa9


  parent reply	other threads:[~2021-10-11 19:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 19:18 [PATCH 1/4] binutils: make objdump/readelf --ctf-parent actually useful Nick Alcock
2021-10-11 19:18 ` [PATCH 2/4] binutils, ld: make objdump --ctf's parameter optional Nick Alcock
2021-10-11 19:18 ` [PATCH 3/4] libctf: dump: do not stop dumping types on error Nick Alcock
2021-10-11 19:18 ` Nick Alcock [this message]
2021-10-12 13:05 ` [PATCH v2] binutils: make objdump/readelf --ctf-parent actually useful Nick Alcock
2021-10-20 22:22   ` Alan Modra
2021-10-21 20:22     ` Nick Alcock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011191810.274535-4-nick.alcock@oracle.com \
    --to=nick.alcock@oracle.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).