Index | Thread | Search

From:
Claudio Jeker <claudio@openbsd.org>
Subject:
ctfconv fix ctt_size for integer and floats
To:
Martin Pieuchot <mpi@openbsd.org>
Cc:
tech@openbsd.org
Date:
Wed, 21 Feb 2024 17:06:08 +0100

Download raw body.

Thread
The ctf spec has:
    2.3.4 Integer types
    Integral types are all represented as types of kind CTF_K_INTEGER.
    These types fill out ctt_size in the ctf_stype_t with the size in
    bytes of the integral type in question.

The same text is used for floating point numbers.

Our ctfconf tool fills in a size in bits not bytes.
I'm not sure if what I did is the best way of handling this. My worry is
that bitfields may show up with e.g. 17bits and that must be rounded up to
a ctt_size of 4.

Now the dummy void object ends up with a size of 1, do we care about that?
-- 
:wq Claudio

Index: generate.c
===================================================================
RCS file: /cvs/src/usr.bin/ctfconv/generate.c,v
diff -u -p -r1.5 generate.c
--- generate.c	14 Aug 2022 14:54:13 -0000	1.5
+++ generate.c	21 Feb 2024 14:35:08 -0000
@@ -196,7 +196,18 @@ imcs_add_type(struct imcs *imcs, struct 
 		ctt.ctt_type = it->it_refp->it_idx;
 		ctsz = sizeof(struct ctf_stype);
 	} else if (size <= CTF_MAX_SIZE) {
-		ctt.ctt_size = size;
+		if (kind == CTF_K_INTEGER || kind == CTF_K_FLOAT) {
+			assert(size <= 64);
+			if (size <= 8)
+				ctt.ctt_size = 1;
+			else if (size <= 16)
+				ctt.ctt_size = 2;
+			else if (size <= 32)
+				ctt.ctt_size = 4;
+			else
+				ctt.ctt_size = 8;
+		} else
+			ctt.ctt_size = size;
 		ctsz = sizeof(struct ctf_stype);
 	} else {
 		ctt.ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);