libctf, ld: fix formatting of forwards to unions and enums
authorNick Alcock <nick.alcock@oracle.com>
Tue, 5 Jan 2021 13:25:56 +0000 (13:25 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Tue, 5 Jan 2021 14:53:40 +0000 (14:53 +0000)
The type printer was unconditionally printing these as if they were
forwards to structs, even if they were forwards to unions or enums.

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

* testsuite/ld-ctf/enum-forward.c: New test.
* testsuite/ld-ctf/enum-forward.c: New results.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

* ctf-types.c (ctf_type_aname): Print forwards to unions and enums
properly.

ld/ChangeLog
ld/testsuite/ld-ctf/enum-forward.c [new file with mode: 0644]
ld/testsuite/ld-ctf/enum-forward.d [new file with mode: 0644]
libctf/ChangeLog
libctf/ctf-types.c

index 213aed02ecb91965ef2ea407182380a4950efb26..b939f616f3a5c8f54bae101196c41b07d5264486 100644 (file)
@@ -1,3 +1,8 @@
+2021-01-05  Nick Alcock  <nick.alcock@oracle.com>
+
+       * testsuite/ld-ctf/enum-forward.c: New test.
+       * testsuite/ld-ctf/enum-forward.c: New results.
+
 2021-01-05  Nick Alcock  <nick.alcock@oracle.com>
 
        * testsuite/ld-ctf/array.d: Adjust for dumper changes.
diff --git a/ld/testsuite/ld-ctf/enum-forward.c b/ld/testsuite/ld-ctf/enum-forward.c
new file mode 100644 (file)
index 0000000..e0a64b8
--- /dev/null
@@ -0,0 +1,2 @@
+enum vibgyor;
+char * (*get_color_name) (enum vibgyor);
diff --git a/ld/testsuite/ld-ctf/enum-forward.d b/ld/testsuite/ld-ctf/enum-forward.d
new file mode 100644 (file)
index 0000000..a83651e
--- /dev/null
@@ -0,0 +1,20 @@
+#as:
+#source: enum-forward.c
+#objdump: --ctf=.ctf
+#ld: -shared
+#name: Forwards to enums
+
+.*: +file format .*
+
+Contents of CTF section .ctf:
+
+  Header:
+    Magic number: 0xdff2
+    Version: 4 \(CTF_VERSION_3\)
+#...
+    Type section:      .* \(0x48 bytes\)
+#...
+  Data objects:
+    get_color_name -> 0x[0-9a-f]*: \(kind 3\) char \*\*\(\*\) \(enum vibgyor\) \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> 0x[0-9a-f]*: \(kind 5\) char \*\(\*\) \(enum vibgyor\) \(aligned at 0x[0-9a-f]*\)
+
+#...
index 4c62cf1f2fa7504c945664be4d1434dbd77fc53b..0aaf3067ab6e63e82401301f4c3ca9a80b671739 100644 (file)
@@ -1,3 +1,8 @@
+2021-01-05  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-types.c (ctf_type_aname): Print forwards to unions and enums
+       properly.
+
 2021-01-05  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-impl.h (ctf_dict_t) <ctf_pptrtab>: New.
index 6275be0058dc483e051191f4e06ee0f525602690..4129fbc7b835507dac3a4a812c69857f0d758316 100644 (file)
@@ -834,7 +834,6 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
              }
              break;
            case CTF_K_STRUCT:
-           case CTF_K_FORWARD:
              ctf_decl_sprintf (&cd, "struct %s", name);
              break;
            case CTF_K_UNION:
@@ -843,6 +842,26 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
            case CTF_K_ENUM:
              ctf_decl_sprintf (&cd, "enum %s", name);
              break;
+           case CTF_K_FORWARD:
+             {
+               switch (ctf_type_kind_forwarded (fp, cdp->cd_type))
+                 {
+                 case CTF_K_STRUCT:
+                   ctf_decl_sprintf (&cd, "struct %s", name);
+                   break;
+                 case CTF_K_UNION:
+                   ctf_decl_sprintf (&cd, "union %s", name);
+                   break;
+                 case CTF_K_ENUM:
+                   ctf_decl_sprintf (&cd, "enum %s", name);
+                   break;
+                 default:
+                   ctf_set_errno (fp, ECTF_CORRUPT);
+                   ctf_decl_fini (&cd);
+                   return NULL;
+                 }
+               break;
+             }
            case CTF_K_VOLATILE:
              ctf_decl_sprintf (&cd, "volatile");
              break;