From: Claudio Jeker Subject: Re: ctfconv fix ctt_size for integer and floats To: Martin Pieuchot , tech@openbsd.org Date: Thu, 22 Feb 2024 12:47:06 +0100 On Wed, Feb 21, 2024 at 05:06:08PM +0100, Claudio Jeker wrote: > 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? This handles the void object a bit better: [1] INTEGER void encoding=SIGNED offset=0 bits=0 -- :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 22 Feb 2024 09:32:12 -0000 @@ -196,7 +196,20 @@ 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 == 0) + ctt.ctt_size = 0; + else 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);