libctf: support encodings for enums
authorNick Alcock <nick.alcock@oracle.com>
Thu, 18 Mar 2021 12:37:52 +0000 (12:37 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Thu, 18 Mar 2021 12:40:41 +0000 (12:40 +0000)
The previous commit started to error-check the lookup of
ctf_type_encoding for the underlying type that is internally done when
carrying out a ctf_type_encoding on a slice.

Unfortunately, enums have no encoding, so this has historically been
returning an error (which is ignored) and then populating the cte_format
with uninitialized data.  Now the error is not ignored, this is
returning an error, which breaks linking of CTF containing bitfields of
enumerated type.

CTF format v3 does not record the actual underlying type of a enum, but
we can mock up something that is not *too* wrong, and that is at any
rate better than uninitialized data.

ld/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

* testsuite/ld-ctf/slice.c: Check slices of enums too.
* testsuite/ld-ctf/slice.d: Results adjusted.

libctf/ChangeLog
2021-03-18  Nick Alcock  <nick.alcock@oracle.com>

* ctf-types.c (ctf_type_encoding): Support, after a fashion, for enums.
* ctf-dump.c (ctf_dump_format_type): Do not report enums' degenerate
encoding.

ld/ChangeLog
ld/testsuite/ld-ctf/slice.c
ld/testsuite/ld-ctf/slice.d
libctf/ChangeLog
libctf/ctf-dump.c
libctf/ctf-types.c

index 7cc917a5128da686e28bfbf300c96be2c6917e43..265f0fb6e7947d410f12353d82491c0d841924ae 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-18  Nick Alcock  <nick.alcock@oracle.com>
+
+       * testsuite/ld-ctf/slice.c: Check slices of enums too.
+       * testsuite/ld-ctf/slice.d: Results adjusted.
+
 2021-03-16  Nick Clifton  <nickc@redhat.com>
 
        * pe-dll.c (pe_find_cdecl_alias_match): Use memmove to overwrite
index 7937bcf796e79a99d1e0d6ef0def6356bada149f..fb38852142e7d6913cc4a575fdd1661598a5722b 100644 (file)
@@ -1,6 +1,9 @@
+enum foo { FOO_BAR };
+
 struct slices {
   int one : 1;
   int two : 2;
   int six : 6;
   int ten :10;
+  enum foo bar:1;
 } slices; 
index d1167828f475767dd13bdc6e1df08782c47d8c03..72a7074f9efca56c057d1539ca33070cddf6a9d5 100644 (file)
@@ -15,7 +15,7 @@ Contents of CTF section .ctf:
     Compilation unit name: .*slice.c
 #...
     Data object section:       .* \(0x4 bytes\)
-    Type section:      .* \(0x9c bytes\)
+    Type section:      .* \(0xd0 bytes\)
     String section:    .*
 #...
   Data objects:
@@ -28,5 +28,5 @@ Contents of CTF section .ctf:
         *\[0x1\] two: ID 0x[0-9a-f]*: \(kind 1\) int:2 \[slice 0x1:0x2\] \(format 0x1\) \(size 0x1\) \(aligned at 0x1\)
         *\[0x3\] six: ID 0x[0-9a-f]*: \(kind 1\) int:6 \[slice 0x3:0x6\] \(format 0x1\) \(size 0x1\) \(aligned at 0x1\)
         *\[0x9\] ten: ID 0x[0-9a-f]*: \(kind 1\) int:10 \[slice 0x9:0xa\] \(format 0x1\) \(size 0x2\) \(aligned at 0x2\)
-
+        *\[0x13\] bar: ID 0x[0-9a-f]*: \(kind 8\) enum foo:1 \[slice 0x13:0x1\] \(format 0x1\) \(size 0x1\) \(aligned at 0x1\)
 #...
index 2d80e781e9756933acf07233f8e6e8d4b2c46e55..d19327ee58a268a31672df31e5b12eddfedd5c48 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-18  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-types.c (ctf_type_encoding): Support, after a fashion, for enums.
+       * ctf-dump.c (ctf_dump_format_type): Do not report enums' degenerate
+       encoding.
+
 2021-03-18  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-dedup.c (ctf_dedup_rhash_type): Report errors on the input
index 409626a224b64974b69989959c6450ec744260fa..8540212eadd4fa8b204bc812742c199f98d29638 100644 (file)
@@ -142,7 +142,10 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
       unsliced_kind = ctf_type_kind_unsliced (fp, id);
       kind = ctf_type_kind (fp, id);
 
-      if (ctf_type_encoding (fp, id, &ep) == 0)
+      /* Report encodings of everything with an encoding other than enums:
+        base-type enums cannot have a nonzero cte_offset or cte_bits value.
+        (Slices of them can, but they are of kind CTF_K_SLICE.)  */
+      if (unsliced_kind != CTF_K_ENUM && ctf_type_encoding (fp, id, &ep) == 0)
        {
          if ((ssize_t) ep.cte_bits != ctf_type_size (fp, id) * CHAR_BIT
              && flag & CTF_FT_BITFIELD)
index ed76eca8463405fc51f80942bcc59df728ad94dc..9afe06ba112db4af14901b470b893354ccdf34fd 100644 (file)
@@ -1157,7 +1157,7 @@ ctf_type_pointer (ctf_dict_t *fp, ctf_id_t type)
   return (ctf_set_errno (ofp, ECTF_NOTYPE));
 }
 
-/* Return the encoding for the specified INTEGER or FLOAT.  */
+/* Return the encoding for the specified INTEGER, FLOAT, or ENUM.  */
 
 int
 ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep)
@@ -1194,6 +1194,12 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep)
       ep->cte_offset = CTF_FP_OFFSET (data);
       ep->cte_bits = CTF_FP_BITS (data);
       break;
+    case CTF_K_ENUM:
+      /* v3 only: we must guess at the underlying integral format.  */
+      ep->cte_format = CTF_INT_SIGNED;
+      ep->cte_offset = 0;
+      ep->cte_bits = 0;
+      break;
     case CTF_K_SLICE:
       {
        const ctf_slice_t *slice;
This page took 0.031593 seconds and 4 git commands to generate.