[v4,32/35] libctf: get the encoding of non-ints/fps in the dynamic space right

Message ID 20190924135131.441906-33-nick.alcock@oracle.com
State New
Headers show
Series
  • CTF linking support
Related show

Commit Message

Nick Alcock Sept. 24, 2019, 1:51 p.m.
If you call ctf_type_encoding() on a slice, you are meant to get the
encoding of the slice with the format of the underlying type.  If
you call it on a non-int, non-fp, non-slice, you're meant to get the
error ECTF_INTNOTFP.

None of this was implemented for types in the dynamic space (which, now,
is *all* types in writable containers).  Instead, we were always
returning the encoding as if it were a float, which for all other types
consulted the wrong part of a discriminated union and returned garbage.
(Curiously, existing users were more disturbed by the lack of an error
in the non-int/fp/slice case than they were about getting garbage back.)

libctf/
	* ctf-types.c (ctf_type_encoding): Fix the dynamic case to
	work right for non-int/fps.
---
 libctf/ctf-types.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

-- 
2.23.0.239.g28aa4420fd

Patch

diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index ec221d73494..27cbfb94d00 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -739,7 +739,27 @@  ctf_type_encoding (ctf_file_t *fp, ctf_id_t type, ctf_encoding_t *ep)
 
   if ((dtd = ctf_dynamic_type (ofp, type)) != NULL)
     {
-      *ep = dtd->dtd_u.dtu_enc;
+      switch (LCTF_INFO_KIND (fp, tp->ctt_info))
+	{
+	case CTF_K_INTEGER:
+	case CTF_K_FLOAT:
+	  *ep = dtd->dtd_u.dtu_enc;
+	  break;
+	case CTF_K_SLICE:
+	  {
+	    const ctf_slice_t *slice;
+	    ctf_encoding_t underlying_en;
+	    slice = &dtd->dtd_u.dtu_slice;
+
+	    data = ctf_type_encoding (fp, slice->cts_type, &underlying_en);
+	    ep->cte_format = underlying_en.cte_format;
+	    ep->cte_offset = slice->cts_offset;
+	    ep->cte_bits = slice->cts_bits;
+	    break;
+	  }
+	default:
+	  return (ctf_set_errno (ofp, ECTF_NOTINTFP));
+	}
       return 0;
     }