138d120bcSMark Johnston.\" 238d120bcSMark Johnston.\" This file and its contents are supplied under the terms of the 338d120bcSMark Johnston.\" Common Development and Distribution License ("CDDL"), version 1.0. 438d120bcSMark Johnston.\" You may only use this file in accordance with the terms of version 538d120bcSMark Johnston.\" 1.0 of the CDDL. 638d120bcSMark Johnston.\" 738d120bcSMark Johnston.\" A full copy of the text of the CDDL should have accompanied this 838d120bcSMark Johnston.\" source. A copy of the CDDL is also available via the Internet at 938d120bcSMark Johnston.\" http://www.illumos.org/license/CDDL. 1038d120bcSMark Johnston.\" 1138d120bcSMark Johnston.\" 1238d120bcSMark Johnston.\" Copyright (c) 2014 Joyent, Inc. 1338d120bcSMark Johnston.\" 14*994297b0SMark Johnston.Dd February 28, 2022 1538d120bcSMark Johnston.Dt CTF 5 1638d120bcSMark Johnston.Os 1738d120bcSMark Johnston.Sh NAME 1838d120bcSMark Johnston.Nm ctf 1938d120bcSMark Johnston.Nd Compact C Type Format 2038d120bcSMark Johnston.Sh SYNOPSIS 2138d120bcSMark Johnston.In sys/ctf.h 2238d120bcSMark Johnston.Sh DESCRIPTION 2338d120bcSMark Johnston.Nm 2438d120bcSMark Johnstonis designed to be a compact representation of the C programming 2538d120bcSMark Johnstonlanguage's type information focused on serving the needs of dynamic 2638d120bcSMark Johnstontracing, debuggers, and other in-situ and post-mortem introspection 2738d120bcSMark Johnstontools. 2838d120bcSMark Johnston.Nm 2938d120bcSMark Johnstondata is generally included in 3038d120bcSMark Johnston.Sy ELF 3138d120bcSMark Johnstonobjects and is tagged as 3238d120bcSMark Johnston.Sy SHT_PROGBITS 3338d120bcSMark Johnstonto ensure that the data is accessible in a running process and in subsequent 3438d120bcSMark Johnstoncore dumps, if generated. 3538d120bcSMark Johnston.Lp 3638d120bcSMark JohnstonThe 3738d120bcSMark Johnston.Nm 3838d120bcSMark Johnstondata contained in each file has information about the layout and 3938d120bcSMark Johnstonsizes of C types, including intrinsic types, enumerations, structures, 4038d120bcSMark Johnstontypedefs, and unions, that are used by the corresponding 4138d120bcSMark Johnston.Sy ELF 42ef36b3f7SMark Johnstonobject. 43ef36b3f7SMark JohnstonThe 4438d120bcSMark Johnston.Nm 4538d120bcSMark Johnstondata may also include information about the types of global objects and 4638d120bcSMark Johnstonthe return type and arguments of functions in the symbol table. 4738d120bcSMark Johnston.Lp 4838d120bcSMark JohnstonBecause a 4938d120bcSMark Johnston.Nm 5038d120bcSMark Johnstonfile is often embedded inside a file, rather than being a standalone 5138d120bcSMark Johnstonfile itself, it may also be referred to as a 5238d120bcSMark Johnston.Nm 5338d120bcSMark Johnston.Sy container . 5438d120bcSMark Johnston.Lp 557421ff07SMark JohnstonOn 567421ff07SMark Johnston.Fx 577421ff07SMark Johnstonsystems, 5838d120bcSMark Johnston.Nm 597421ff07SMark Johnstondata is consumed by 60ef36b3f7SMark Johnston.Xr dtrace 1 . 6138d120bcSMark JohnstonProgrammatic access to 6238d120bcSMark Johnston.Nm 637421ff07SMark Johnstondata can be obtained through libctf. 6438d120bcSMark Johnston.Lp 6538d120bcSMark JohnstonThe 6638d120bcSMark Johnston.Nm 67ef36b3f7SMark Johnstonfile format is broken down into seven different sections. 68*994297b0SMark JohnstonThe first two sections are the 6938d120bcSMark Johnston.Sy preamble 7038d120bcSMark Johnstonand 7138d120bcSMark Johnston.Sy header , 72*994297b0SMark Johnstonwhich describe the version of the 7338d120bcSMark Johnston.Nm 747421ff07SMark Johnstonfile, the links it has to other 7538d120bcSMark Johnston.Nm 76ef36b3f7SMark Johnstonfiles, and the sizes of the other sections. 77ef36b3f7SMark JohnstonThe next section is the 7838d120bcSMark Johnston.Sy label 7938d120bcSMark Johnstonsection, 8038d120bcSMark Johnstonwhich provides a way of identifying similar groups of 8138d120bcSMark Johnston.Nm 82ef36b3f7SMark Johnstondata across multiple files. 83ef36b3f7SMark JohnstonThis is followed by the 8438d120bcSMark Johnston.Sy object 857421ff07SMark Johnstoninformation section, which describes the types of global 86ef36b3f7SMark Johnstonsymbols. 87ef36b3f7SMark JohnstonThe subsequent section is the 8838d120bcSMark Johnston.Sy function 8938d120bcSMark Johnstoninformation section, which describes the return 90ef36b3f7SMark Johnstontypes and arguments of functions. 91ef36b3f7SMark JohnstonThe next section is the 9238d120bcSMark Johnston.Sy type 9338d120bcSMark Johnstoninformation section, which describes 9438d120bcSMark Johnstonthe format and layout of the C types themselves, and finally the last 9538d120bcSMark Johnstonsection is the 9638d120bcSMark Johnston.Sy string 9738d120bcSMark Johnstonsection, which contains the names of types, enumerations, members, and 9838d120bcSMark Johnstonlabels. 9938d120bcSMark Johnston.Lp 10038d120bcSMark JohnstonWhile strictly speaking, only the 10138d120bcSMark Johnston.Sy preamble 10238d120bcSMark Johnstonand 10338d120bcSMark Johnston.Sy header 10438d120bcSMark Johnstonare required, to be actually useful, both the type and string 10538d120bcSMark Johnstonsections are necessary. 10638d120bcSMark Johnston.Lp 10738d120bcSMark JohnstonA 10838d120bcSMark Johnston.Nm 10938d120bcSMark Johnstonfile may contain all of the type information that it requires, or it 11038d120bcSMark Johnstonmay optionally refer to another 11138d120bcSMark Johnston.Nm 112ef36b3f7SMark Johnstonfile which holds the remaining types. 113ef36b3f7SMark JohnstonWhen a 11438d120bcSMark Johnston.Nm 11538d120bcSMark Johnstonfile refers to another file, it is called the 11638d120bcSMark Johnston.Sy child 11738d120bcSMark Johnstonand the file it refers to is called the 11838d120bcSMark Johnston.Sy parent . 119ef36b3f7SMark JohnstonA given file may only refer to one parent. 120ef36b3f7SMark JohnstonThis process is called 12138d120bcSMark Johnston.Em uniquification 12238d120bcSMark Johnstonbecause it ensures each child only has type information that is 123ef36b3f7SMark Johnstonunique to it. 124ef36b3f7SMark JohnstonA common example of this is that most kernel modules in illumos are uniquified 125ef36b3f7SMark Johnstonagainst the kernel module 12638d120bcSMark Johnston.Sy genunix 12738d120bcSMark Johnstonand the type information that comes from the 12838d120bcSMark Johnston.Sy IP 129ef36b3f7SMark Johnstonmodule. 130ef36b3f7SMark JohnstonThis means that a module only has types that are unique to itself and the most 131ef36b3f7SMark Johnstoncommon types in the kernel are not duplicated. 132*994297b0SMark JohnstonUniquification is not used when building kernel modules on 133*994297b0SMark Johnston.Fx . 13438d120bcSMark Johnston.Sh FILE FORMAT 13538d120bcSMark JohnstonThis documents version 136*994297b0SMark Johnston.Em three 13738d120bcSMark Johnstonof the 13838d120bcSMark Johnston.Nm 139ef36b3f7SMark Johnstonfile format. 140*994297b0SMark JohnstonThe 141*994297b0SMark Johnston.Xr ctfconvert 1 142*994297b0SMark Johnstonand 143*994297b0SMark Johnston.Xr ctfmerge 1 144*994297b0SMark Johnstonutilities emit 145*994297b0SMark Johnston.Nm 146*994297b0SMark Johnstonversion 3, and all other applications and libraries can operate on 147*994297b0SMark Johnstonversions 2 and 3. 14838d120bcSMark Johnston.Lp 14938d120bcSMark JohnstonThe file format can be summarized with the following image, the 15038d120bcSMark Johnstonfollowing sections will cover this in more detail. 15138d120bcSMark Johnston.Bd -literal 15238d120bcSMark Johnston 15338d120bcSMark Johnston +-------------+ 0t0 15438d120bcSMark Johnston+--------| Preamble | 15538d120bcSMark Johnston| +-------------+ 0t4 15638d120bcSMark Johnston|+-------| Header | 15738d120bcSMark Johnston|| +-------------+ 0t36 + cth_lbloff 15838d120bcSMark Johnston||+------| Labels | 15938d120bcSMark Johnston||| +-------------+ 0t36 + cth_objtoff 16038d120bcSMark Johnston|||+-----| Objects | 16138d120bcSMark Johnston|||| +-------------+ 0t36 + cth_funcoff 16238d120bcSMark Johnston||||+----| Functions | 16338d120bcSMark Johnston||||| +-------------+ 0t36 + cth_typeoff 16438d120bcSMark Johnston|||||+---| Types | 16538d120bcSMark Johnston|||||| +-------------+ 0t36 + cth_stroff 16638d120bcSMark Johnston||||||+--| Strings | 16738d120bcSMark Johnston||||||| +-------------+ 0t36 + cth_stroff + cth_strlen 16838d120bcSMark Johnston||||||| 16938d120bcSMark Johnston||||||| 17038d120bcSMark Johnston||||||| 17138d120bcSMark Johnston||||||| +-- magic - vers flags 17238d120bcSMark Johnston||||||| | | | | 17338d120bcSMark Johnston||||||| +------+------+------+------+ 174*994297b0SMark Johnston+---------| 0xcf | 0xf1 | 0x03 | 0x00 | 17538d120bcSMark Johnston |||||| +------+------+------+------+ 17638d120bcSMark Johnston |||||| 0 1 2 3 4 17738d120bcSMark Johnston |||||| 17838d120bcSMark Johnston |||||| + parent label + objects 17938d120bcSMark Johnston |||||| | + parent name | + functions + strings 18038d120bcSMark Johnston |||||| | | + label | | + types | + strlen 18138d120bcSMark Johnston |||||| | | | | | | | | 18238d120bcSMark Johnston |||||| +------+------+------+------+------+-------+-------+-------+ 18338d120bcSMark Johnston +--------| 0x00 | 0x00 | 0x00 | 0x08 | 0x36 | 0x110 | 0x5f4 | 0x611 | 18438d120bcSMark Johnston ||||| +------+------+------+------+------+-------+-------+-------+ 18538d120bcSMark Johnston ||||| 0x04 0x08 0x0c 0x10 0x14 0x18 0x1c 0x20 0x24 18638d120bcSMark Johnston ||||| 18738d120bcSMark Johnston ||||| + Label name 18838d120bcSMark Johnston ||||| | + Label type 18938d120bcSMark Johnston ||||| | | + Next label 19038d120bcSMark Johnston ||||| | | | 19138d120bcSMark Johnston ||||| +-------+------+-----+ 19238d120bcSMark Johnston +-----------| 0x01 | 0x42 | ... | 19338d120bcSMark Johnston |||| +-------+------+-----+ 19438d120bcSMark Johnston |||| cth_lbloff +0x4 +0x8 cth_objtoff 19538d120bcSMark Johnston |||| 19638d120bcSMark Johnston |||| 19738d120bcSMark Johnston |||| Symidx 0t15 0t43 0t44 19838d120bcSMark Johnston |||| +------+------+------+-----+ 19938d120bcSMark Johnston +----------| 0x00 | 0x42 | 0x36 | ... | 20038d120bcSMark Johnston ||| +------+------+------+-----+ 201*994297b0SMark Johnston ||| cth_objtoff +0x4 +0x8 +0xc cth_funcoff 20238d120bcSMark Johnston ||| 20338d120bcSMark Johnston ||| + CTF_TYPE_INFO + CTF_TYPE_INFO 20438d120bcSMark Johnston ||| | + Return type | 20538d120bcSMark Johnston ||| | | + arg0 | 20638d120bcSMark Johnston ||| +--------+------+------+-----+ 20738d120bcSMark Johnston +---------| 0x2c10 | 0x08 | 0x0c | ... | 20838d120bcSMark Johnston || +--------+------+------+-----+ 209*994297b0SMark Johnston || cth_funcff +0x4 +0x8 +0xc cth_typeoff 21038d120bcSMark Johnston || 21138d120bcSMark Johnston || + ctf_stype_t for type 1 21238d120bcSMark Johnston || | integer + integer encoding 21338d120bcSMark Johnston || | | + ctf_stype_t for type 2 21438d120bcSMark Johnston || | | | 21538d120bcSMark Johnston || +--------------------+-----------+-----+ 21638d120bcSMark Johnston +--------| 0x19 * 0xc01 * 0x0 | 0x1000000 | ... | 21738d120bcSMark Johnston | +--------------------+-----------+-----+ 218*994297b0SMark Johnston | cth_typeoff +0x0c +0x10 cth_stroff 21938d120bcSMark Johnston | 22038d120bcSMark Johnston | +--- str 0 22138d120bcSMark Johnston | | +--- str 1 + str 2 22238d120bcSMark Johnston | | | | 22338d120bcSMark Johnston | v v v 22438d120bcSMark Johnston | +----+---+---+---+----+---+---+---+---+---+----+ 22538d120bcSMark Johnston +---| \\0 | i | n | t | \\0 | f | o | o | _ | t | \\0 | 22638d120bcSMark Johnston +----+---+---+---+----+---+---+---+---+---+----+ 22738d120bcSMark Johnston 0 1 2 3 4 5 6 7 8 9 10 11 22838d120bcSMark Johnston.Ed 22938d120bcSMark Johnston.Lp 23038d120bcSMark JohnstonEvery 23138d120bcSMark Johnston.Nm 23238d120bcSMark Johnstonfile begins with a 23338d120bcSMark Johnston.Sy preamble , 23438d120bcSMark Johnstonfollowed by a 23538d120bcSMark Johnston.Sy header . 23638d120bcSMark JohnstonThe 23738d120bcSMark Johnston.Sy preamble 23838d120bcSMark Johnstonis defined as follows: 23938d120bcSMark Johnston.Bd -literal 24038d120bcSMark Johnstontypedef struct ctf_preamble { 241d6eb9861SMark Johnston uint16_t ctp_magic; /* magic number (CTF_MAGIC) */ 242d6eb9861SMark Johnston uint8_t ctp_version; /* data format version number (CTF_VERSION) */ 243d6eb9861SMark Johnston uint8_t ctp_flags; /* flags (see below) */ 24438d120bcSMark Johnston} ctf_preamble_t; 24538d120bcSMark Johnston.Ed 24638d120bcSMark Johnston.Pp 24738d120bcSMark JohnstonThe 24838d120bcSMark Johnston.Sy preamble 24938d120bcSMark Johnstonis four bytes long and must be four byte aligned. 25038d120bcSMark JohnstonThis 25138d120bcSMark Johnston.Sy preamble 25238d120bcSMark Johnstondefines the version of the 25338d120bcSMark Johnston.Nm 254ef36b3f7SMark Johnstonfile which defines the format of the rest of the header. 255ef36b3f7SMark JohnstonWhile the header may change in subsequent versions, the preamble will not change 25638d120bcSMark Johnstonacross versions, though the interpretation of its flags may change from 257ef36b3f7SMark Johnstonversion to version. 258ef36b3f7SMark JohnstonThe 25938d120bcSMark Johnston.Em ctp_magic 26038d120bcSMark Johnstonmember defines the magic number for the 26138d120bcSMark Johnston.Nm 262ef36b3f7SMark Johnstonfile format. 263ef36b3f7SMark JohnstonThis must always be 26438d120bcSMark Johnston.Li 0xcff1 . 26538d120bcSMark JohnstonIf another value is encountered, then the file should not be treated as 26638d120bcSMark Johnstona 26738d120bcSMark Johnston.Nm 268ef36b3f7SMark Johnstonfile. 269ef36b3f7SMark JohnstonThe 27038d120bcSMark Johnston.Em ctp_version 27138d120bcSMark Johnstonmember defines the version of the 27238d120bcSMark Johnston.Nm 273ef36b3f7SMark Johnstonfile. 274ef36b3f7SMark JohnstonThe current version is 275*994297b0SMark Johnston.Li 3 . 276ef36b3f7SMark JohnstonIt is possible to encounter an unsupported version. 277ef36b3f7SMark JohnstonIn that case, software should not try to parse the format, as it may have 278ef36b3f7SMark Johnstonchanged. 27938d120bcSMark JohnstonFinally, the 28038d120bcSMark Johnston.Em ctp_flags 28138d120bcSMark Johnstonmember describes aspects of the file which modify its interpretation. 28238d120bcSMark JohnstonThe following flags are currently defined: 28338d120bcSMark Johnston.Bd -literal 28438d120bcSMark Johnston#define CTF_F_COMPRESS 0x01 28538d120bcSMark Johnston.Ed 28638d120bcSMark Johnston.Pp 28738d120bcSMark JohnstonThe flag 28838d120bcSMark Johnston.Sy CTF_F_COMPRESS 28938d120bcSMark Johnstonindicates that the body of the 29038d120bcSMark Johnston.Nm 29138d120bcSMark Johnstonfile, all the data following the 29238d120bcSMark Johnston.Sy header , 29338d120bcSMark Johnstonhas been compressed through the 29438d120bcSMark Johnston.Sy zlib 29538d120bcSMark Johnstonlibrary and its 29638d120bcSMark Johnston.Sy deflate 297ef36b3f7SMark Johnstonalgorithm. 298ef36b3f7SMark JohnstonIf this flag is not present, then the body has not been compressed and no 299ef36b3f7SMark Johnstonspecial action is needed to interpret it. 300ef36b3f7SMark JohnstonAll offsets into the data as described by 30138d120bcSMark Johnston.Sy header , 30238d120bcSMark Johnstonalways refer to the 30338d120bcSMark Johnston.Sy uncompressed 30438d120bcSMark Johnstondata. 30538d120bcSMark Johnston.Lp 306*994297b0SMark JohnstonIn versions two and three of the 30738d120bcSMark Johnston.Nm 30838d120bcSMark Johnstonfile format, the 30938d120bcSMark Johnston.Sy header 3107421ff07SMark Johnstondenotes whether or not this 31138d120bcSMark Johnston.Nm 31238d120bcSMark Johnstonfile is the child of another 31338d120bcSMark Johnston.Nm 314ef36b3f7SMark Johnstonfile and also indicates the size of the remaining sections. 315ef36b3f7SMark JohnstonThe structure for the 3167421ff07SMark Johnston.Sy header 31738d120bcSMark Johnstonlogically contains a copy of the 31838d120bcSMark Johnston.Sy preamble 31938d120bcSMark Johnstonand the two have a combined size of 36 bytes. 32038d120bcSMark Johnston.Bd -literal 32138d120bcSMark Johnstontypedef struct ctf_header { 32238d120bcSMark Johnston ctf_preamble_t cth_preamble; 323d6eb9861SMark Johnston uint32_t cth_parlabel; /* ref to name of parent lbl uniq'd against */ 324d6eb9861SMark Johnston uint32_t cth_parname; /* ref to basename of parent */ 325d6eb9861SMark Johnston uint32_t cth_lbloff; /* offset of label section */ 326d6eb9861SMark Johnston uint32_t cth_objtoff; /* offset of object section */ 327d6eb9861SMark Johnston uint32_t cth_funcoff; /* offset of function section */ 328d6eb9861SMark Johnston uint32_t cth_typeoff; /* offset of type section */ 329d6eb9861SMark Johnston uint32_t cth_stroff; /* offset of string section */ 330d6eb9861SMark Johnston uint32_t cth_strlen; /* length of string section in bytes */ 33138d120bcSMark Johnston} ctf_header_t; 33238d120bcSMark Johnston.Ed 33338d120bcSMark Johnston.Pp 33438d120bcSMark JohnstonAfter the 33538d120bcSMark Johnston.Sy preamble , 33638d120bcSMark Johnstonthe next two members 337*994297b0SMark Johnston.Em cth_parlabel 33838d120bcSMark Johnstonand 33938d120bcSMark Johnston.Em cth_parname , 340ef36b3f7SMark Johnstonare used to identify the parent. 341ef36b3f7SMark JohnstonThe value of both members are offsets into the 34238d120bcSMark Johnston.Sy string 343ef36b3f7SMark Johnstonsection which point to the start of a null-terminated string. 344ef36b3f7SMark JohnstonFor more information on the encoding of strings, see the subsection on 34538d120bcSMark Johnston.Sx String Identifiers . 34638d120bcSMark JohnstonIf the value of either is zero, then there is no entry for that 347ef36b3f7SMark Johnstonmember. 348ef36b3f7SMark JohnstonIf the member 34938d120bcSMark Johnston.Em cth_parlabel 35038d120bcSMark Johnstonis set, then the 35138d120bcSMark Johnston.Em ctf_parname 35238d120bcSMark Johnstonmember must be set, otherwise it will not be possible to find the 353ef36b3f7SMark Johnstonparent. 354ef36b3f7SMark JohnstonIf 35538d120bcSMark Johnston.Em ctf_parname 35638d120bcSMark Johnstonis set, it is not necessary to define 35738d120bcSMark Johnston.Em cth_parlabel , 358ef36b3f7SMark Johnstonas the parent may not have a label. 359ef36b3f7SMark JohnstonFor more information on labels and their interpretation, see 36038d120bcSMark Johnston.Sx The Label Section . 36138d120bcSMark Johnston.Lp 36238d120bcSMark JohnstonThe remaining members (excepting 36338d120bcSMark Johnston.Em cth_strlen ) 364ef36b3f7SMark Johnstondescribe the beginning of the corresponding sections. 365ef36b3f7SMark JohnstonThese offsets are relative to the end of the 36638d120bcSMark Johnston.Sy header . 36738d120bcSMark JohnstonTherefore, something with an offset of 0 is at an offset of thirty-six 36838d120bcSMark Johnstonbytes relative to the start of the 36938d120bcSMark Johnston.Nm 370ef36b3f7SMark Johnstonfile. 371ef36b3f7SMark JohnstonThe difference between members indicates the size of the section itself. 372ef36b3f7SMark JohnstonDifferent offsets have different alignment requirements. 373ef36b3f7SMark JohnstonThe start of the 374*994297b0SMark Johnston.Em cth_objtoff 37538d120bcSMark Johnstonand 37638d120bcSMark Johnston.Em cth_funcoff 37738d120bcSMark Johnstonmust be two byte aligned, while the sections 37838d120bcSMark Johnston.Em cth_lbloff 37938d120bcSMark Johnstonand 38038d120bcSMark Johnston.Em cth_typeoff 381ef36b3f7SMark Johnstonmust be four-byte aligned. 382ef36b3f7SMark JohnstonThe section 38338d120bcSMark Johnston.Em cth_stroff 384ef36b3f7SMark Johnstonhas no alignment requirements. 385ef36b3f7SMark JohnstonTo calculate the size of a given section, excepting the 38638d120bcSMark Johnston.Sy string 387ef36b3f7SMark Johnstonsection, one should subtract the offset of the section from the following one. 388ef36b3f7SMark JohnstonFor example, the size of the 38938d120bcSMark Johnston.Sy types 39038d120bcSMark Johnstonsection can be calculated by subtracting 391*994297b0SMark Johnston.Em cth_typeoff 39238d120bcSMark Johnstonfrom 393*994297b0SMark Johnston.Em cth_stroff . 39438d120bcSMark Johnston.Lp 39538d120bcSMark JohnstonFinally, the member 39638d120bcSMark Johnston.Em cth_strlen 397ef36b3f7SMark Johnstondescribes the length of the string section itself. 398ef36b3f7SMark JohnstonFrom it, you can also calculate the size of the entire 39938d120bcSMark Johnston.Nm 40038d120bcSMark Johnstonfile by adding together the size of the 40138d120bcSMark Johnston.Sy ctf_header_t , 40238d120bcSMark Johnstonthe offset of the string section in 40338d120bcSMark Johnston.Em cth_stroff , 40438d120bcSMark Johnstonand the size of the string section in 40538d120bcSMark Johnston.Em cth_srlen . 40638d120bcSMark Johnston.Ss Type Identifiers 40738d120bcSMark JohnstonThrough the 40838d120bcSMark Johnston.Nm ctf 409ef36b3f7SMark Johnstondata, types are referred to by identifiers. 410ef36b3f7SMark JohnstonA given 41138d120bcSMark Johnston.Nm 412*994297b0SMark Johnstonfile supports up to 2147483646 (0x7ffffffe) types. 413*994297b0SMark Johnston.Nm 414*994297b0SMark Johnstonversion 2 had a much smaller limit of 32767 types. 415ef36b3f7SMark JohnstonThe first valid type identifier is 0x1. 41638d120bcSMark JohnstonWhen a given 41738d120bcSMark Johnston.Nm 41838d120bcSMark Johnstonfile is a child, indicated by a non-zero entry for the 41938d120bcSMark Johnston.Sy header Ns 's 42038d120bcSMark Johnston.Em cth_parname , 421*994297b0SMark Johnstonthen the first valid type identifier is 0x80000000 and the last is 0xfffffffe. 422*994297b0SMark JohnstonIn this case, type identifiers 0x1 through 0x7ffffffe are references to the 42338d120bcSMark Johnstonparent. 424*994297b0SMark Johnston0x7fffffff and 0xffffffff are not treated as valid type identifiers so as to 425*994297b0SMark Johnstonenable the use of -1 as an error value. 42638d120bcSMark Johnston.Lp 42738d120bcSMark JohnstonThe type identifier zero is a sentinel value used to indicate that there 42838d120bcSMark Johnstonis no type information available or it is an unknown type. 42938d120bcSMark Johnston.Lp 43038d120bcSMark JohnstonThroughout the file format, the identifier is stored in different sized 43138d120bcSMark Johnstonvalues; however, the minimum size to represent a given identifier is a 43238d120bcSMark Johnston.Sy uint16_t . 43338d120bcSMark JohnstonOther consumers of 43438d120bcSMark Johnston.Nm 43538d120bcSMark Johnstoninformation may use larger or opaque identifiers. 43638d120bcSMark Johnston.Ss String Identifiers 43738d120bcSMark JohnstonString identifiers are always encoded as four byte unsigned integers 438ef36b3f7SMark Johnstonwhich are an offset into a string table. 439ef36b3f7SMark JohnstonThe 44038d120bcSMark Johnston.Nm 44138d120bcSMark Johnstonformat supports two different string tables which have an identifier of 442ef36b3f7SMark Johnstonzero or one. 443ef36b3f7SMark JohnstonThis identifier is stored in the high-order bit of the unsigned four byte 444ef36b3f7SMark Johnstonoffset. 445ef36b3f7SMark JohnstonTherefore, the maximum supported offset into one of these tables is 0x7ffffffff. 44638d120bcSMark Johnston.Lp 44738d120bcSMark JohnstonTable identifier zero, always refers to the 44838d120bcSMark Johnston.Sy string 449ef36b3f7SMark Johnstonsection in the CTF file itself. 450ef36b3f7SMark JohnstonString table identifier one refers to an external string table which is the ELF 451ef36b3f7SMark Johnstonstring table for the ELF symbol table associated with the 45238d120bcSMark Johnston.Nm 45338d120bcSMark Johnstoncontainer. 45438d120bcSMark Johnston.Ss Type Encoding 45538d120bcSMark JohnstonEvery 45638d120bcSMark Johnston.Nm 45738d120bcSMark Johnstontype begins with metadata encoded into a 458*994297b0SMark Johnston.Sy uint32_t . 45938d120bcSMark JohnstonThis encoded information tells us three different pieces of information: 46038d120bcSMark Johnston.Bl -bullet -offset indent -compact 46138d120bcSMark Johnston.It 46238d120bcSMark JohnstonThe kind of the type 46338d120bcSMark Johnston.It 46438d120bcSMark JohnstonWhether this type is a root type or not 46538d120bcSMark Johnston.It 46638d120bcSMark JohnstonThe length of the variable data 46738d120bcSMark Johnston.El 46838d120bcSMark Johnston.Lp 469*994297b0SMark JohnstonThe 32 bits that make up the encoding are broken down into six bits 470*994297b0SMark Johnstonfor the kind (bits 26 to 31), one bit for the root type flag (bit 25), 471*994297b0SMark Johnstonand 25 bits for the length of the variable data. 47238d120bcSMark Johnston.Lp 473ef36b3f7SMark JohnstonThe current version of the file format defines 14 different kinds. 474ef36b3f7SMark JohnstonThe interpretation of these different kinds will be discussed in the section 47538d120bcSMark Johnston.Sx The Type Section . 47638d120bcSMark JohnstonIf a kind is encountered that is not listed below, then it is not a valid 47738d120bcSMark Johnston.Nm 478ef36b3f7SMark Johnstonfile. 479ef36b3f7SMark JohnstonThe kinds are defined as follows: 48038d120bcSMark Johnston.Bd -literal -offset indent 48138d120bcSMark Johnston#define CTF_K_UNKNOWN 0 48238d120bcSMark Johnston#define CTF_K_INTEGER 1 48338d120bcSMark Johnston#define CTF_K_FLOAT 2 48438d120bcSMark Johnston#define CTF_K_POINTER 3 48538d120bcSMark Johnston#define CTF_K_ARRAY 4 48638d120bcSMark Johnston#define CTF_K_FUNCTION 5 48738d120bcSMark Johnston#define CTF_K_STRUCT 6 48838d120bcSMark Johnston#define CTF_K_UNION 7 48938d120bcSMark Johnston#define CTF_K_ENUM 8 49038d120bcSMark Johnston#define CTF_K_FORWARD 9 49138d120bcSMark Johnston#define CTF_K_TYPEDEF 10 49238d120bcSMark Johnston#define CTF_K_VOLATILE 11 49338d120bcSMark Johnston#define CTF_K_CONST 12 49438d120bcSMark Johnston#define CTF_K_RESTRICT 13 49538d120bcSMark Johnston.Ed 49638d120bcSMark Johnston.Lp 49738d120bcSMark JohnstonPrograms directly reference many types; however, other types are referenced 498ef36b3f7SMark Johnstonindirectly because they are part of some other structure. 499ef36b3f7SMark JohnstonThese types that are referenced directly and used are called 50038d120bcSMark Johnston.Sy root 501ef36b3f7SMark Johnstontypes. 502ef36b3f7SMark JohnstonOther types may be used indirectly, for example, a program may reference 503ef36b3f7SMark Johnstona structure directly, but not one of its members which has a type. 504ef36b3f7SMark JohnstonThat type is not considered a 50538d120bcSMark Johnston.Sy root 506ef36b3f7SMark Johnstontype. 507ef36b3f7SMark JohnstonIf a type is a 50838d120bcSMark Johnston.Sy root 509*994297b0SMark Johnstontype, then it will have bit 25 set. 51038d120bcSMark Johnston.Lp 51138d120bcSMark JohnstonThe variable length section is specific to each kind and is discussed in the 51238d120bcSMark Johnstonsection 51338d120bcSMark Johnston.Sx The Type Section . 51438d120bcSMark Johnston.Lp 51538d120bcSMark JohnstonThe following macros are useful for constructing and deconstructing the encoded 51638d120bcSMark Johnstontype information: 51738d120bcSMark Johnston.Bd -literal -offset indent 51838d120bcSMark Johnston 519*994297b0SMark Johnston#define CTF_V3_MAX_VLEN 0x00ffffff 520*994297b0SMark Johnston#define CTF_V3_INFO_KIND(info) (((info) & 0xfc000000) >> 26) 521*994297b0SMark Johnston#define CTF_V3_INFO_ISROOT(info) (((info) & 0x02000000) >> 25) 522*994297b0SMark Johnston#define CTF_V3_INFO_VLEN(info) (((info) & CTF_V3_MAX_VLEN)) 52338d120bcSMark Johnston 524*994297b0SMark Johnston#define CTF_V3_TYPE_INFO(kind, isroot, vlen) \\ 525*994297b0SMark Johnston (((kind) << 26) | (((isroot) ? 1 : 0) << 25) | ((vlen) & CTF_V3_MAX_VLEN)) 52638d120bcSMark Johnston.Ed 52738d120bcSMark Johnston.Ss The Label Section 52838d120bcSMark JohnstonWhen consuming 52938d120bcSMark Johnston.Nm 53038d120bcSMark Johnstondata, it is often useful to know whether two different 53138d120bcSMark Johnston.Nm 532ef36b3f7SMark Johnstoncontainers come from the same source base and version. 533ef36b3f7SMark JohnstonFor example, when building illumos, there are many kernel modules that are built 534ef36b3f7SMark Johnstonagainst a single collection of source code. 535ef36b3f7SMark JohnstonA label is encoded into the 53638d120bcSMark Johnston.Nm 537ef36b3f7SMark Johnstonfiles that corresponds with the particular build. 538ef36b3f7SMark JohnstonThis ensures that if files on the system were to become mixed up from multiple 539ef36b3f7SMark Johnstonreleases, that they are not used together by tools, particularly when a child 540ef36b3f7SMark Johnstonneeds to refer to a type in the parent. 5417421ff07SMark JohnstonBecause they are linked using the type identifiers, if the wrong parent is used 542ef36b3f7SMark Johnstonthen the wrong type will be encountered. 543*994297b0SMark JohnstonNote that this mechanism is not currently used on 544*994297b0SMark Johnston.Fx . 545*994297b0SMark JohnstonIn particular, kernel modules built on 546*994297b0SMark Johnston.Fx 547*994297b0SMark Johnstoneach contain a complete type graph. 54838d120bcSMark Johnston.Lp 54938d120bcSMark JohnstonEach label is encoded in the file format using the following eight byte 55038d120bcSMark Johnstonstructure: 55138d120bcSMark Johnston.Bd -literal 55238d120bcSMark Johnstontypedef struct ctf_lblent { 553d6eb9861SMark Johnston uint32_t ctl_label; /* ref to name of label */ 554d6eb9861SMark Johnston uint32_t ctl_typeidx; /* last type associated with this label */ 55538d120bcSMark Johnston} ctf_lblent_t; 55638d120bcSMark Johnston.Ed 55738d120bcSMark Johnston.Lp 55838d120bcSMark JohnstonEach label has two different components, a name and a type identifier. 55938d120bcSMark JohnstonThe name is encoded in the 56038d120bcSMark Johnston.Em ctl_label 56138d120bcSMark Johnstonmember which is in the format defined in the section 56238d120bcSMark Johnston.Sx String Identifiers . 56338d120bcSMark JohnstonGenerally, the names of all labels are found in the internal string 56438d120bcSMark Johnstonsection. 56538d120bcSMark Johnston.Lp 56638d120bcSMark JohnstonThe type identifier encoded in the member 56738d120bcSMark Johnston.Em ctl_typeidx 56838d120bcSMark Johnstonrefers to the last type identifier that a label refers to in the current 569ef36b3f7SMark Johnstonfile. 570ef36b3f7SMark JohnstonLabels only refer to types in the current file, if the 57138d120bcSMark Johnston.Nm 57238d120bcSMark Johnstonfile is a child, then it will have the same label as its parent; 5737421ff07SMark Johnstonhowever, its label will only refer to its types, not its parent's. 57438d120bcSMark Johnston.Lp 57538d120bcSMark JohnstonIt is also possible, though rather uncommon, for a 57638d120bcSMark Johnston.Nm 577ef36b3f7SMark Johnstonfile to have multiple labels. 578ef36b3f7SMark JohnstonLabels are placed one after another, every eight bytes. 579ef36b3f7SMark JohnstonWhen multiple labels are present, types may only belong to a single label. 58038d120bcSMark Johnston.Ss The Object Section 58138d120bcSMark JohnstonThe object section provides a mapping from ELF symbols of type 58238d120bcSMark Johnston.Sy STT_OBJECT 583ef36b3f7SMark Johnstonin the symbol table to a type identifier. 584ef36b3f7SMark JohnstonEvery entry in this section is a 585*994297b0SMark Johnston.Sy uint32_t 58638d120bcSMark Johnstonwhich contains a type identifier as described in the section 58738d120bcSMark Johnston.Sx Type Identifiers . 58838d120bcSMark JohnstonIf there is no information for an object, then the type identifier 0x0 58938d120bcSMark Johnstonis stored for that entry. 59038d120bcSMark Johnston.Lp 59138d120bcSMark JohnstonTo walk the object section, you need to have a corresponding 59238d120bcSMark Johnston.Sy symbol table 59338d120bcSMark Johnstonin the ELF object that contains the 59438d120bcSMark Johnston.Nm 595ef36b3f7SMark Johnstondata. 596ef36b3f7SMark JohnstonNot every object is included in this section. 5977421ff07SMark JohnstonSpecifically, when walking the symbol table, an entry is skipped if it matches 5987421ff07SMark Johnstonany of the following conditions: 59938d120bcSMark Johnston.Lp 60038d120bcSMark Johnston.Bl -bullet -offset indent -compact 60138d120bcSMark Johnston.It 60238d120bcSMark JohnstonThe symbol type is not 60338d120bcSMark Johnston.Sy STT_OBJECT 60438d120bcSMark Johnston.It 60538d120bcSMark JohnstonThe symbol's section index is 60638d120bcSMark Johnston.Sy SHN_UNDEF 60738d120bcSMark Johnston.It 60838d120bcSMark JohnstonThe symbol's name offset is zero 60938d120bcSMark Johnston.It 61038d120bcSMark JohnstonThe symbol's section index is 61138d120bcSMark Johnston.Sy SHN_ABS 61238d120bcSMark Johnstonand the value of the symbol is zero. 61338d120bcSMark Johnston.It 61438d120bcSMark JohnstonThe symbol's name is 61538d120bcSMark Johnston.Li _START_ 61638d120bcSMark Johnstonor 61738d120bcSMark Johnston.Li _END_ . 61838d120bcSMark JohnstonThese are skipped because they are used for scoping local symbols in 61938d120bcSMark JohnstonELF. 62038d120bcSMark Johnston.El 62138d120bcSMark Johnston.Lp 62238d120bcSMark JohnstonThe following sample code shows an example of iterating the object 62338d120bcSMark Johnstonsection and skipping the correct symbols: 62438d120bcSMark Johnston.Bd -literal 62538d120bcSMark Johnston#include <gelf.h> 62638d120bcSMark Johnston#include <stdio.h> 62738d120bcSMark Johnston 62838d120bcSMark Johnston/* 629*994297b0SMark Johnston * Given the start of the object section in a CTFv3 file, the number of symbols, 63038d120bcSMark Johnston * and the ELF Data sections for the symbol table and the string table, this 63138d120bcSMark Johnston * prints the type identifiers that correspond to objects. Note, a more robust 63238d120bcSMark Johnston * implementation should ensure that they don't walk beyond the end of the CTF 63338d120bcSMark Johnston * object section. 634*994297b0SMark Johnston * 635*994297b0SMark Johnston * An implementation that handles CTFv2 must take into account the fact that 636*994297b0SMark Johnston * type identifiers are 16 bits wide rather than 32 bits wide. 63738d120bcSMark Johnston */ 63838d120bcSMark Johnstonstatic int 639*994297b0SMark Johnstonwalk_symbols(uint32_t *objtoff, Elf_Data *symdata, Elf_Data *strdata, 64038d120bcSMark Johnston long nsyms) 64138d120bcSMark Johnston{ 64238d120bcSMark Johnston long i; 64338d120bcSMark Johnston uintptr_t strbase = strdata->d_buf; 64438d120bcSMark Johnston 64538d120bcSMark Johnston for (i = 1; i < nsyms; i++, objftoff++) { 64638d120bcSMark Johnston const char *name; 64738d120bcSMark Johnston GElf_Sym sym; 64838d120bcSMark Johnston 64938d120bcSMark Johnston if (gelf_getsym(symdata, i, &sym) == NULL) 65038d120bcSMark Johnston return (1); 65138d120bcSMark Johnston 65238d120bcSMark Johnston if (GELF_ST_TYPE(sym.st_info) != STT_OBJECT) 65338d120bcSMark Johnston continue; 65438d120bcSMark Johnston if (sym.st_shndx == SHN_UNDEF || sym.st_name == 0) 65538d120bcSMark Johnston continue; 65638d120bcSMark Johnston if (sym.st_shndx == SHN_ABS && sym.st_value == 0) 65738d120bcSMark Johnston continue; 65838d120bcSMark Johnston name = (const char *)(strbase + sym.st_name); 65938d120bcSMark Johnston if (strcmp(name, "_START_") == 0 || strcmp(name, "_END_") == 0) 66038d120bcSMark Johnston continue; 66138d120bcSMark Johnston 66238d120bcSMark Johnston (void) printf("Symbol %d has type %d\n", i, *objtoff); 66338d120bcSMark Johnston } 66438d120bcSMark Johnston 66538d120bcSMark Johnston return (0); 66638d120bcSMark Johnston} 66738d120bcSMark Johnston.Ed 66838d120bcSMark Johnston.Ss The Function Section 66938d120bcSMark JohnstonThe function section of the 67038d120bcSMark Johnston.Nm 67138d120bcSMark Johnstonfile encodes the types of both the function's arguments and the function's 6727421ff07SMark Johnstonreturn value. 673ef36b3f7SMark JohnstonSimilar to 67438d120bcSMark Johnston.Sx The Object Section , 67538d120bcSMark Johnstonthe function section encodes information for all symbols of type 67638d120bcSMark Johnston.Sy STT_FUNCTION , 677ef36b3f7SMark Johnstonexcepting those that fit specific criteria. 678ef36b3f7SMark JohnstonUnlike with objects, because functions have a variable number of arguments, they 679ef36b3f7SMark Johnstonstart with a type encoding as defined in 68038d120bcSMark Johnston.Sx Type Encoding , 68138d120bcSMark Johnstonwhich is the size of a 682*994297b0SMark Johnston.Sy uint32_t . 68338d120bcSMark JohnstonFor functions which have no type information available, they are encoded as 684*994297b0SMark Johnston.Li CTF_V3_TYPE_INFO(CTF_K_UNKNOWN, 0, 0) . 685ef36b3f7SMark JohnstonFunctions with arguments are encoded differently. 686ef36b3f7SMark JohnstonHere, the variable length is turned into the number of arguments in the 687ef36b3f7SMark Johnstonfunction. 688ef36b3f7SMark JohnstonIf a function is a 68938d120bcSMark Johnston.Sy varargs 690ef36b3f7SMark Johnstontype function, then the number of arguments is increased by one. 691ef36b3f7SMark JohnstonFunctions with type information are encoded as: 692*994297b0SMark Johnston.Li CTF_V3_TYPE_INFO(CTF_K_FUNCTION, 0, nargs) . 69338d120bcSMark Johnston.Lp 69438d120bcSMark JohnstonFor functions that have no type information, nothing else is encoded, and the 695ef36b3f7SMark Johnstonnext function is encoded. 696ef36b3f7SMark JohnstonFor functions with type information, the next 697*994297b0SMark Johnston.Sy uint32_t 698ef36b3f7SMark Johnstonis encoded with the type identifier of the return type of the function. 699ef36b3f7SMark JohnstonIt is followed by each of the type identifiers of the arguments, if any exist, 700ef36b3f7SMark Johnstonin the order that they appear in the function. 701ef36b3f7SMark JohnstonTherefore, argument 0 is the first type identifier and so on. 702ef36b3f7SMark JohnstonWhen a function has a final varargs argument, that is encoded with the type 703ef36b3f7SMark Johnstonidentifier of zero. 70438d120bcSMark Johnston.Lp 70538d120bcSMark JohnstonLike 70638d120bcSMark Johnston.Sx The Object Section , 707ef36b3f7SMark Johnstonthe function section is encoded in the order of the symbol table. 708ef36b3f7SMark JohnstonIt has similar, but slightly different considerations from objects. 709ef36b3f7SMark JohnstonWhile iterating the symbol table, if any of the following conditions are true, 710ef36b3f7SMark Johnstonthen the entry is skipped and no corresponding entry is written: 71138d120bcSMark Johnston.Lp 71238d120bcSMark Johnston.Bl -bullet -offset indent -compact 71338d120bcSMark Johnston.It 71438d120bcSMark JohnstonThe symbol type is not 71538d120bcSMark Johnston.Sy STT_FUNCTION 71638d120bcSMark Johnston.It 71738d120bcSMark JohnstonThe symbol's section index is 71838d120bcSMark Johnston.Sy SHN_UNDEF 71938d120bcSMark Johnston.It 72038d120bcSMark JohnstonThe symbol's name offset is zero 72138d120bcSMark Johnston.It 72238d120bcSMark JohnstonThe symbol's name is 72338d120bcSMark Johnston.Li _START_ 72438d120bcSMark Johnstonor 72538d120bcSMark Johnston.Li _END_ . 72638d120bcSMark JohnstonThese are skipped because they are used for scoping local symbols in 72738d120bcSMark JohnstonELF. 72838d120bcSMark Johnston.El 72938d120bcSMark Johnston.Ss The Type Section 73038d120bcSMark JohnstonThe type section is the heart of the 73138d120bcSMark Johnston.Nm 732ef36b3f7SMark Johnstondata. 733ef36b3f7SMark JohnstonIt encodes all of the information about the types themselves. 734ef36b3f7SMark JohnstonThe base of the type information comes in two forms, a short form and a long 735ef36b3f7SMark Johnstonform, each of which may be followed by a variable number of arguments. 736ef36b3f7SMark JohnstonThe following definitions describe the short and long forms: 73738d120bcSMark Johnston.Bd -literal 738*994297b0SMark Johnston#define CTF_V3_MAX_SIZE 0xfffffffe /* max size of a type in bytes */ 739*994297b0SMark Johnston#define CTF_V3_LSIZE_SENT 0xffffffff /* sentinel for ctt_size */ 740*994297b0SMark Johnston#define CTF_V3_MAX_LSIZE UINT64_MAX 74138d120bcSMark Johnston 742*994297b0SMark Johnstonstruct ctf_stype_v3 { 743d6eb9861SMark Johnston uint32_t ctt_name; /* reference to name in string table */ 744*994297b0SMark Johnston uint32_t ctt_info; /* encoded kind, variant length */ 74538d120bcSMark Johnston union { 746*994297b0SMark Johnston uint32_t _size; /* size of entire type in bytes */ 747*994297b0SMark Johnston uint32_t _type; /* reference to another type */ 74838d120bcSMark Johnston } _u; 749*994297b0SMark Johnston}; 75038d120bcSMark Johnston 751*994297b0SMark Johnstonstruct ctf_type_v3 { 752d6eb9861SMark Johnston uint32_t ctt_name; /* reference to name in string table */ 753*994297b0SMark Johnston uint32_t ctt_info; /* encoded kind, variant length */ 75438d120bcSMark Johnston union { 755*994297b0SMark Johnston uint32_t _size; /* always CTF_LSIZE_SENT */ 756*994297b0SMark Johnston uint32_t _type; /* do not use */ 75738d120bcSMark Johnston } _u; 758d6eb9861SMark Johnston uint32_t ctt_lsizehi; /* high 32 bits of type size in bytes */ 759d6eb9861SMark Johnston uint32_t ctt_lsizelo; /* low 32 bits of type size in bytes */ 760*994297b0SMark Johnston}; 76138d120bcSMark Johnston 76238d120bcSMark Johnston#define ctt_size _u._size /* for fundamental types that have a size */ 76338d120bcSMark Johnston#define ctt_type _u._type /* for types that reference another type */ 76438d120bcSMark Johnston.Ed 76538d120bcSMark Johnston.Pp 76638d120bcSMark JohnstonType sizes are stored in 76738d120bcSMark Johnston.Sy bytes . 76838d120bcSMark JohnstonThe basic small form uses a 769*994297b0SMark Johnston.Sy uint32_t 770ef36b3f7SMark Johnstonto store the number of bytes. 771*994297b0SMark JohnstonIf the number of bytes in a structure would exceed 0xfffffffe, then the 772*994297b0SMark Johnstonalternate form, the 773*994297b0SMark Johnston.Sy struct ctf_type_v3 , 774ef36b3f7SMark Johnstonis used instead. 775ef36b3f7SMark JohnstonTo indicate that the larger form is being used, the member 77638d120bcSMark Johnston.Em ctt_size 77738d120bcSMark Johnstonis set to value of 778*994297b0SMark Johnston.Sy CTF_V3_LSIZE_SENT 779*994297b0SMark Johnston(0xffffffff). 780ef36b3f7SMark JohnstonIn general, when going through the type section, consumers use the 781*994297b0SMark Johnston.Sy struct ctf_type_v3 78238d120bcSMark Johnstonstructure, but pay attention to the value of the member 78338d120bcSMark Johnston.Em ctt_size 784*994297b0SMark Johnstonto determine whether they should increment their scan by the size of 785*994297b0SMark Johnston.Sy struct ctf_stype_v3 78638d120bcSMark Johnstonor 787*994297b0SMark Johnston.Sy struct ctf_type_v3 . 78838d120bcSMark JohnstonNot all kinds of types use 78938d120bcSMark Johnston.Sy ctt_size . 79038d120bcSMark JohnstonThose which do not, will always use the 791*994297b0SMark Johnston.Sy struct ctf_stype_v3 792ef36b3f7SMark Johnstonstructure. 793ef36b3f7SMark JohnstonThe individual sections for each kind have more information. 79438d120bcSMark Johnston.Lp 795ef36b3f7SMark JohnstonTypes are written out in order. 796ef36b3f7SMark JohnstonTherefore the first entry encountered has a type id of 0x1, or 0x8000 if a 797ef36b3f7SMark Johnstonchild. 798ef36b3f7SMark JohnstonThe member 79938d120bcSMark Johnston.Em ctt_name 80038d120bcSMark Johnstonis encoded as described in the section 80138d120bcSMark Johnston.Sx String Identifiers . 802ef36b3f7SMark JohnstonThe string that it points to is the name of the type. 803ef36b3f7SMark JohnstonIf the identifier points to an empty string (one that consists solely of a null 804ef36b3f7SMark Johnstonterminator) then the type does not have a name, this is common with anonymous 8057421ff07SMark Johnstonstructures and unions that only have a typedef to name them, as well as 806ef36b3f7SMark Johnstonpointers and qualifiers. 80738d120bcSMark Johnston.Lp 80838d120bcSMark JohnstonThe next member, the 80938d120bcSMark Johnston.Em ctt_info , 81038d120bcSMark Johnstonis encoded as described in the section 81138d120bcSMark Johnston.Sx Type Encoding . 8127421ff07SMark JohnstonThe type's kind tells us how to interpret the remaining data in the 813*994297b0SMark Johnston.Sy struct ctf_type_v3 814ef36b3f7SMark Johnstonand any variable length data that may exist. 815ef36b3f7SMark JohnstonThe rest of this section will be broken down into the interpretation of the 816ef36b3f7SMark Johnstonvarious kinds. 81738d120bcSMark Johnston.Ss Encoding of Integers 81838d120bcSMark JohnstonIntegers, which are of type 81938d120bcSMark Johnston.Sy CTF_K_INTEGER , 820ef36b3f7SMark Johnstonhave no variable length arguments. 821d6eb9861SMark JohnstonInstead, they are followed by a 822d6eb9861SMark Johnston.Sy uint32_t 823ef36b3f7SMark Johnstonwhich describes their encoding. 824ef36b3f7SMark JohnstonAll integers must be encoded with a variable length of zero. 825ef36b3f7SMark JohnstonThe 82638d120bcSMark Johnston.Em ctt_size 827ef36b3f7SMark Johnstonmember describes the length of the integer in bytes. 828ef36b3f7SMark JohnstonIn general, integer sizes will be rounded up to the closest power of two. 82938d120bcSMark Johnston.Lp 83038d120bcSMark JohnstonThe integer encoding contains three different pieces of information: 83138d120bcSMark Johnston.Bl -bullet -offset indent -compact 83238d120bcSMark Johnston.It 83338d120bcSMark JohnstonThe encoding of the integer 83438d120bcSMark Johnston.It 83538d120bcSMark JohnstonThe offset in 83638d120bcSMark Johnston.Sy bits 83738d120bcSMark Johnstonof the type 83838d120bcSMark Johnston.It 83938d120bcSMark JohnstonThe size in 84038d120bcSMark Johnston.Sy bits 84138d120bcSMark Johnstonof the type 84238d120bcSMark Johnston.El 84338d120bcSMark Johnston.Pp 84438d120bcSMark JohnstonThis encoding can be expressed through the following macros: 84538d120bcSMark Johnston.Bd -literal -offset indent 84638d120bcSMark Johnston#define CTF_INT_ENCODING(data) (((data) & 0xff000000) >> 24) 84738d120bcSMark Johnston#define CTF_INT_OFFSET(data) (((data) & 0x00ff0000) >> 16) 84838d120bcSMark Johnston#define CTF_INT_BITS(data) (((data) & 0x0000ffff)) 84938d120bcSMark Johnston 85038d120bcSMark Johnston#define CTF_INT_DATA(encoding, offset, bits) \\ 85138d120bcSMark Johnston (((encoding) << 24) | ((offset) << 16) | (bits)) 85238d120bcSMark Johnston.Ed 85338d120bcSMark Johnston.Pp 85438d120bcSMark JohnstonThe following flags are defined for the encoding at this time: 85538d120bcSMark Johnston.Bd -literal -offset indent 85638d120bcSMark Johnston#define CTF_INT_SIGNED 0x01 85738d120bcSMark Johnston#define CTF_INT_CHAR 0x02 85838d120bcSMark Johnston#define CTF_INT_BOOL 0x04 85938d120bcSMark Johnston#define CTF_INT_VARARGS 0x08 86038d120bcSMark Johnston.Ed 86138d120bcSMark Johnston.Lp 86238d120bcSMark JohnstonBy default, an integer is considered to be unsigned, unless it has the 86338d120bcSMark Johnston.Sy CTF_INT_SIGNED 864ef36b3f7SMark Johnstonflag set. 865ef36b3f7SMark JohnstonIf the flag 86638d120bcSMark Johnston.Sy CTF_INT_CHAR 86738d120bcSMark Johnstonis set, that indicates that the integer is of a type that stores character 86838d120bcSMark Johnstondata, for example the intrinsic C type 86938d120bcSMark Johnston.Sy char 87038d120bcSMark Johnstonwould have the 87138d120bcSMark Johnston.Sy CTF_INT_CHAR 872ef36b3f7SMark Johnstonflag set. 873ef36b3f7SMark JohnstonIf the flag 87438d120bcSMark Johnston.Sy CTF_INT_BOOL 875ef36b3f7SMark Johnstonis set, that indicates that the integer represents a boolean type. 876ef36b3f7SMark JohnstonFor example, the intrinsic C type 87738d120bcSMark Johnston.Sy _Bool 87838d120bcSMark Johnstonwould have the 87938d120bcSMark Johnston.Sy CTF_INT_BOOL 880ef36b3f7SMark Johnstonflag set. 881ef36b3f7SMark JohnstonFinally, the flag 88238d120bcSMark Johnston.Sy CTF_INT_VARARGS 88338d120bcSMark Johnstonindicates that the integer is used as part of a variable number of arguments. 88438d120bcSMark JohnstonThis encoding is rather uncommon. 88538d120bcSMark Johnston.Ss Encoding of Floats 88638d120bcSMark JohnstonFloats, which are of type 88738d120bcSMark Johnston.Sy CTF_K_FLOAT , 888ef36b3f7SMark Johnstonare similar to their integer counterparts. 889ef36b3f7SMark JohnstonThey have no variable length arguments and are followed by a four byte encoding 890ef36b3f7SMark Johnstonwhich describes the kind of float that exists. 891ef36b3f7SMark JohnstonThe 89238d120bcSMark Johnston.Em ctt_size 893ef36b3f7SMark Johnstonmember is the size, in bytes, of the float. 894ef36b3f7SMark JohnstonThe float encoding has three different pieces of information inside of it: 89538d120bcSMark Johnston.Lp 89638d120bcSMark Johnston.Bl -bullet -offset indent -compact 89738d120bcSMark Johnston.It 89838d120bcSMark JohnstonThe specific kind of float that exists 89938d120bcSMark Johnston.It 90038d120bcSMark JohnstonThe offset in 90138d120bcSMark Johnston.Sy bits 90238d120bcSMark Johnstonof the float 90338d120bcSMark Johnston.It 90438d120bcSMark JohnstonThe size in 90538d120bcSMark Johnston.Sy bits 90638d120bcSMark Johnstonof the float 90738d120bcSMark Johnston.El 90838d120bcSMark Johnston.Lp 90938d120bcSMark JohnstonThis encoding can be expressed through the following macros: 91038d120bcSMark Johnston.Bd -literal -offset indent 91138d120bcSMark Johnston#define CTF_FP_ENCODING(data) (((data) & 0xff000000) >> 24) 91238d120bcSMark Johnston#define CTF_FP_OFFSET(data) (((data) & 0x00ff0000) >> 16) 91338d120bcSMark Johnston#define CTF_FP_BITS(data) (((data) & 0x0000ffff)) 91438d120bcSMark Johnston 91538d120bcSMark Johnston#define CTF_FP_DATA(encoding, offset, bits) \\ 91638d120bcSMark Johnston (((encoding) << 24) | ((offset) << 16) | (bits)) 91738d120bcSMark Johnston.Ed 91838d120bcSMark Johnston.Lp 9197421ff07SMark JohnstonWhere as the encoding for integers is a series of flags, the encoding for 920ef36b3f7SMark Johnstonfloats maps to a specific kind of float. 921ef36b3f7SMark JohnstonIt is not a flag-based value. 922ef36b3f7SMark JohnstonThe kinds of floats correspond to both their size, and the encoding. 923ef36b3f7SMark JohnstonThis covers all of the basic C intrinsic floating point types. 924ef36b3f7SMark JohnstonThe following are the different kinds of floats represented in the encoding: 92538d120bcSMark Johnston.Bd -literal -offset indent 92638d120bcSMark Johnston#define CTF_FP_SINGLE 1 /* IEEE 32-bit float encoding */ 92738d120bcSMark Johnston#define CTF_FP_DOUBLE 2 /* IEEE 64-bit float encoding */ 92838d120bcSMark Johnston#define CTF_FP_CPLX 3 /* Complex encoding */ 92938d120bcSMark Johnston#define CTF_FP_DCPLX 4 /* Double complex encoding */ 93038d120bcSMark Johnston#define CTF_FP_LDCPLX 5 /* Long double complex encoding */ 93138d120bcSMark Johnston#define CTF_FP_LDOUBLE 6 /* Long double encoding */ 93238d120bcSMark Johnston#define CTF_FP_INTRVL 7 /* Interval (2x32-bit) encoding */ 93338d120bcSMark Johnston#define CTF_FP_DINTRVL 8 /* Double interval (2x64-bit) encoding */ 93438d120bcSMark Johnston#define CTF_FP_LDINTRVL 9 /* Long double interval (2x128-bit) encoding */ 93538d120bcSMark Johnston#define CTF_FP_IMAGRY 10 /* Imaginary (32-bit) encoding */ 93638d120bcSMark Johnston#define CTF_FP_DIMAGRY 11 /* Long imaginary (64-bit) encoding */ 93738d120bcSMark Johnston#define CTF_FP_LDIMAGRY 12 /* Long double imaginary (128-bit) encoding */ 93838d120bcSMark Johnston.Ed 93938d120bcSMark Johnston.Ss Encoding of Arrays 94038d120bcSMark JohnstonArrays, which are of type 94138d120bcSMark Johnston.Sy CTF_K_ARRAY , 942ef36b3f7SMark Johnstonhave no variable length arguments. 943ef36b3f7SMark JohnstonThey are followed by a structure which describes the number of elements in the 944ef36b3f7SMark Johnstonarray, the type identifier of the elements in the array, and the type identifier 945ef36b3f7SMark Johnstonof the index of the array. 946ef36b3f7SMark JohnstonWith arrays, the 94738d120bcSMark Johnston.Em ctt_size 948ef36b3f7SMark Johnstonmember is set to zero. 949ef36b3f7SMark JohnstonThe structure that follows an array is defined as: 95038d120bcSMark Johnston.Bd -literal 951*994297b0SMark Johnstonstruct ctf_array_v3 { 952*994297b0SMark Johnston uint32_t cta_contents; /* reference to type of array contents */ 953*994297b0SMark Johnston uint32_t cta_index; /* reference to type of array index */ 954d6eb9861SMark Johnston uint32_t cta_nelems; /* number of elements */ 955*994297b0SMark Johnston}; 95638d120bcSMark Johnston.Ed 95738d120bcSMark Johnston.Lp 95838d120bcSMark JohnstonThe 95938d120bcSMark Johnston.Em cta_contents 96038d120bcSMark Johnstonand 96138d120bcSMark Johnston.Em cta_index 96238d120bcSMark Johnstonmembers of the 963*994297b0SMark Johnston.Sy struct ctf_array_v3 96438d120bcSMark Johnstonare type identifiers which are encoded as per the section 96538d120bcSMark Johnston.Sx Type Identifiers . 96638d120bcSMark JohnstonThe member 96738d120bcSMark Johnston.Em cta_nelems 968ef36b3f7SMark Johnstonis a simple four byte unsigned count of the number of elements. 969ef36b3f7SMark JohnstonThis count may be zero when encountering C99's flexible array members. 97038d120bcSMark Johnston.Ss Encoding of Functions 97138d120bcSMark JohnstonFunction types, which are of type 97238d120bcSMark Johnston.Sy CTF_K_FUNCTION , 973ef36b3f7SMark Johnstonuse the variable length list to be the number of arguments in the function. 974ef36b3f7SMark JohnstonWhen the function has a final member which is a varargs, then the argument count 975ef36b3f7SMark Johnstonis incremented by one to account for the variable argument. 976ef36b3f7SMark JohnstonHere, the 97738d120bcSMark Johnston.Em ctt_type 97838d120bcSMark Johnstonmember is encoded with the type identifier of the return type of the function. 97938d120bcSMark JohnstonNote that the 98038d120bcSMark Johnston.Em ctt_size 98138d120bcSMark Johnstonmember is not used here. 98238d120bcSMark Johnston.Lp 98338d120bcSMark JohnstonThe variable argument list contains the type identifiers for the arguments of 984ef36b3f7SMark Johnstonthe function, if any. 985ef36b3f7SMark JohnstonEach one is represented by a 986*994297b0SMark Johnston.Sy uint32_t 98738d120bcSMark Johnstonand encoded according to the 98838d120bcSMark Johnston.Sx Type Identifiers 989ef36b3f7SMark Johnstonsection. 990ef36b3f7SMark JohnstonIf the function's last argument is of type varargs, then it is also written out, 991ef36b3f7SMark Johnstonbut the type identifier is zero. 992ef36b3f7SMark JohnstonThis is included in the count of the function's arguments. 993*994297b0SMark JohnstonIn 994*994297b0SMark Johnston.Nm 995*994297b0SMark Johnstonversion 2, an extra type identifier may follow the argument and return type 996*994297b0SMark Johnstonidentifiers in order to maintain four-byte alignment for the following type 997*994297b0SMark Johnstondefinition. 9987421ff07SMark JohnstonSuch a type identifier is not included in the argument count and has a value 9997421ff07SMark Johnstonof zero. 1000*994297b0SMark JohnstonIn 1001*994297b0SMark Johnston.Nm 1002*994297b0SMark Johnstonversion 3, four-byte alignment occurs naturally and no padding is used. 100338d120bcSMark Johnston.Ss Encoding of Structures and Unions 100438d120bcSMark JohnstonStructures and Unions, which are encoded with 100538d120bcSMark Johnston.Sy CTF_K_STRUCT 100638d120bcSMark Johnstonand 100738d120bcSMark Johnston.Sy CTF_K_UNION 1008ef36b3f7SMark Johnstonrespectively, are very similar constructs in C. 10097421ff07SMark JohnstonThe main difference between them is the fact that members of a structure 10107421ff07SMark Johnstonfollow one another, where as in a union, all members share the same memory. 1011ef36b3f7SMark JohnstonThey are also very similar in terms of their encoding in 101238d120bcSMark Johnston.Nm . 101338d120bcSMark JohnstonThe variable length argument for structures and unions represents the number of 1014ef36b3f7SMark Johnstonmembers that they have. 1015ef36b3f7SMark JohnstonThe value of the member 101638d120bcSMark Johnston.Em ctt_size 1017ef36b3f7SMark Johnstonis the size of the structure and union. 1018ef36b3f7SMark JohnstonThere are two different structures which are used to encode members in the 1019ef36b3f7SMark Johnstonvariable list. 1020ef36b3f7SMark JohnstonWhen the size of a structure or union is greater than or equal to the large 1021*994297b0SMark Johnstonmember threshold, 536870912, then a different structure is used to encode the 1022*994297b0SMark Johnstonmember; all members are encoded using the same structure. 1023ef36b3f7SMark JohnstonThe structure for members is as follows: 102438d120bcSMark Johnston.Bd -literal 1025*994297b0SMark Johnstonstruct ctf_member_v3 { 1026d6eb9861SMark Johnston uint32_t ctm_name; /* reference to name in string table */ 1027*994297b0SMark Johnston uint32_t ctm_type; /* reference to type of member */ 1028*994297b0SMark Johnston uint32_t ctm_offset; /* offset of this member in bits */ 1029*994297b0SMark Johnston}; 103038d120bcSMark Johnston 1031*994297b0SMark Johnstonstruct ctf_lmember_v3 { 1032d6eb9861SMark Johnston uint32_t ctlm_name; /* reference to name in string table */ 1033*994297b0SMark Johnston uint32_t ctlm_type; /* reference to type of member */ 1034d6eb9861SMark Johnston uint32_t ctlm_offsethi; /* high 32 bits of member offset in bits */ 1035d6eb9861SMark Johnston uint32_t ctlm_offsetlo; /* low 32 bits of member offset in bits */ 1036*994297b0SMark Johnston}; 103738d120bcSMark Johnston.Ed 103838d120bcSMark Johnston.Lp 103938d120bcSMark JohnstonBoth the 104038d120bcSMark Johnston.Em ctm_name 104138d120bcSMark Johnstonand 104238d120bcSMark Johnston.Em ctlm_name 1043ef36b3f7SMark Johnstonrefer to the name of the member. 1044ef36b3f7SMark JohnstonThe name is encoded as an offset into the string table as described by the 1045ef36b3f7SMark Johnstonsection 104638d120bcSMark Johnston.Sx String Identifiers . 104738d120bcSMark JohnstonThe members 104838d120bcSMark Johnston.Sy ctm_type 104938d120bcSMark Johnstonand 105038d120bcSMark Johnston.Sy ctlm_type 1051ef36b3f7SMark Johnstonboth refer to the type of the member. 1052ef36b3f7SMark JohnstonThey are encoded as per the section 105338d120bcSMark Johnston.Sx Type Identifiers . 105438d120bcSMark Johnston.Lp 105538d120bcSMark JohnstonThe last piece of information that is present is the offset which describes the 10567421ff07SMark Johnstonoffset in memory at which the member begins. 10577421ff07SMark JohnstonFor unions, this value will always be zero because each member of a union has 10587421ff07SMark Johnstonan offset of zero. 1059ef36b3f7SMark JohnstonFor structures, this is the offset in 106038d120bcSMark Johnston.Sy bits 10617421ff07SMark Johnstonat which the member begins. 1062ef36b3f7SMark JohnstonNote that a compiler may lay out a type with padding. 106338d120bcSMark JohnstonThis means that the difference in offset between two consecutive members may be 1064ef36b3f7SMark Johnstonlarger than the size of the member. 1065*994297b0SMark JohnstonWhen the size of the overall structure is strictly less than 536870912 bytes, 1066*994297b0SMark Johnstonthe normal structure, 1067*994297b0SMark Johnston.Sy struct ctf_member_v3 , 106838d120bcSMark Johnstonis used and the offset in bits is stored in the member 106938d120bcSMark Johnston.Em ctm_offset . 1070*994297b0SMark JohnstonHowever, when the size of the structure is greater than or equal to 536870912 1071*994297b0SMark Johnstonbytes, then the number of bits is split into two 32-bit quantities. 1072ef36b3f7SMark JohnstonOne member, 107338d120bcSMark Johnston.Em ctlm_offsethi , 107438d120bcSMark Johnstonrepresents the upper 32 bits of the offset, while the other member, 107538d120bcSMark Johnston.Em ctlm_offsetlo , 1076ef36b3f7SMark Johnstonrepresents the lower 32 bits of the offset. 1077ef36b3f7SMark JohnstonThese can be joined together to get a 64-bit sized offset in bits by shifting 1078ef36b3f7SMark Johnstonthe member 107938d120bcSMark Johnston.Em ctlm_offsethi 108038d120bcSMark Johnstonto the left by thirty two and then doing a binary or of 108138d120bcSMark Johnston.Em ctlm_offsetlo . 108238d120bcSMark Johnston.Ss Encoding of Enumerations 108338d120bcSMark JohnstonEnumerations, noted by the type 108438d120bcSMark Johnston.Sy CTF_K_ENUM , 1085ef36b3f7SMark Johnstonare similar to structures. 1086ef36b3f7SMark JohnstonEnumerations use the variable list to note the number of values that the 1087ef36b3f7SMark Johnstonenumeration contains, which we'll term enumerators. 1088ef36b3f7SMark JohnstonIn C, an enumeration is always equivalent to the intrinsic type 108938d120bcSMark Johnston.Sy int , 109038d120bcSMark Johnstonthus the value of the member 109138d120bcSMark Johnston.Em ctt_size 109238d120bcSMark Johnstonis always the size of an integer which is determined based on the current model. 10937421ff07SMark JohnstonFor 10947421ff07SMark Johnston.Fx 10957421ff07SMark Johnstonsystems, this will always be 4, as an integer is always defined to 109638d120bcSMark Johnstonbe 4 bytes large in both 109738d120bcSMark Johnston.Sy ILP32 109838d120bcSMark Johnstonand 109938d120bcSMark Johnston.Sy LP64 , 110038d120bcSMark Johnstonregardless of the architecture. 11017421ff07SMark JohnstonFor further details, see 11027421ff07SMark Johnston.Xr arch 7 . 110338d120bcSMark Johnston.Lp 110438d120bcSMark JohnstonThe enumerators encoded in an enumeration have the following structure in the 110538d120bcSMark Johnstonvariable list: 110638d120bcSMark Johnston.Bd -literal 110738d120bcSMark Johnstontypedef struct ctf_enum { 1108d6eb9861SMark Johnston uint32_t cte_name; /* reference to name in string table */ 1109d6eb9861SMark Johnston int32_t cte_value; /* value associated with this name */ 111038d120bcSMark Johnston} ctf_enum_t; 111138d120bcSMark Johnston.Ed 111238d120bcSMark Johnston.Pp 111338d120bcSMark JohnstonThe member 111438d120bcSMark Johnston.Em cte_name 111538d120bcSMark Johnstonrefers to the name of the enumerator's value, it is encoded according to the 111638d120bcSMark Johnstonrules in the section 111738d120bcSMark Johnston.Sx String Identifiers . 111838d120bcSMark JohnstonThe member 111938d120bcSMark Johnston.Em cte_value 112038d120bcSMark Johnstoncontains the integer value of this enumerator. 112138d120bcSMark Johnston.Ss Encoding of Forward References 112238d120bcSMark JohnstonForward references, types of kind 112338d120bcSMark Johnston.Sy CTF_K_FORWARD , 112438d120bcSMark Johnstonin a 112538d120bcSMark Johnston.Nm 1126ef36b3f7SMark Johnstonfile refer to types which may not have a definition at all, only a name. 1127ef36b3f7SMark JohnstonIf the 112838d120bcSMark Johnston.Nm 112938d120bcSMark Johnstonfile is a child, then it may be that the forward is resolved to an 113038d120bcSMark Johnstonactual type in the parent, otherwise the definition may be in another 113138d120bcSMark Johnston.Nm 1132ef36b3f7SMark Johnstoncontainer or may not be known at all. 1133ef36b3f7SMark JohnstonThe only member of the 1134*994297b0SMark Johnston.Sy struct ctf_type_v3 113538d120bcSMark Johnstonthat matters for a forward declaration is the 113638d120bcSMark Johnston.Em ctt_name 113738d120bcSMark Johnstonwhich points to the name of the forward reference in the string table as 1138ef36b3f7SMark Johnstondescribed earlier. 1139ef36b3f7SMark JohnstonThere is no other information recorded for forward references. 114038d120bcSMark Johnston.Ss Encoding of Pointers, Typedefs, Volatile, Const, and Restrict 114138d120bcSMark JohnstonPointers, typedefs, volatile, const, and restrict are all similar in 114238d120bcSMark Johnston.Nm . 1143ef36b3f7SMark JohnstonThey all refer to another type. 1144ef36b3f7SMark JohnstonIn the case of typedefs, they provide an alternate name, while volatile, const, 1145ef36b3f7SMark Johnstonand restrict change how the type is interpreted in the C programming language. 1146ef36b3f7SMark JohnstonThis covers the 114738d120bcSMark Johnston.Nm 114838d120bcSMark Johnstonkinds 114938d120bcSMark Johnston.Sy CTF_K_POINTER , 115038d120bcSMark Johnston.Sy CTF_K_TYPEDEF , 115138d120bcSMark Johnston.Sy CTF_K_VOLATILE , 115238d120bcSMark Johnston.Sy CTF_K_RESTRICT , 115338d120bcSMark Johnstonand 115438d120bcSMark Johnston.Sy CTF_K_CONST . 115538d120bcSMark Johnston.Lp 115638d120bcSMark JohnstonThese types have no variable list entries and use the member 115738d120bcSMark Johnston.Em ctt_type 115838d120bcSMark Johnstonto refer to the base type that they modify. 115938d120bcSMark Johnston.Ss Encoding of Unknown Types 116038d120bcSMark JohnstonTypes with the kind 116138d120bcSMark Johnston.Sy CTF_K_UNKNOWN 1162ef36b3f7SMark Johnstonare used to indicate gaps in the type identifier space. 1163ef36b3f7SMark JohnstonThese entries consume an identifier, but do not define anything. 1164ef36b3f7SMark JohnstonNothing should refer to these gap identifiers. 116538d120bcSMark Johnston.Ss Dependencies Between Types 1166ef36b3f7SMark JohnstonC types can be imagined as a directed, cyclic, graph. 1167ef36b3f7SMark JohnstonStructures and unions may refer to each other in a way that creates a cyclic 1168ef36b3f7SMark Johnstondependency. 1169ef36b3f7SMark JohnstonIn cases such as these, the entire type section must be read in and processed. 1170ef36b3f7SMark JohnstonConsumers must not assume that every type can be laid out in dependency order; 1171ef36b3f7SMark Johnstonthey cannot. 117238d120bcSMark Johnston.Ss The String Section 117338d120bcSMark JohnstonThe last section of the 117438d120bcSMark Johnston.Nm 117538d120bcSMark Johnstonfile is the 117638d120bcSMark Johnston.Sy string 1177ef36b3f7SMark Johnstonsection. 1178ef36b3f7SMark JohnstonThis section encodes all of the strings that appear throughout the other 1179ef36b3f7SMark Johnstonsections. 1180ef36b3f7SMark JohnstonIt is laid out as a series of characters followed by a null terminator. 1181ef36b3f7SMark JohnstonGenerally, all names are written out in ASCII, as most C compilers do not allow 11827421ff07SMark Johnstonany characters to appear in identifiers outside of a subset of ASCII. 1183ef36b3f7SMark JohnstonHowever, any extended characters sets should be written out as a series of UTF-8 1184ef36b3f7SMark Johnstonbytes. 118538d120bcSMark Johnston.Lp 118638d120bcSMark JohnstonThe first entry in the section, at offset zero, is a single null 1187ef36b3f7SMark Johnstonterminator to reference the empty string. 1188ef36b3f7SMark JohnstonFollowing that, each C string should be written out, including the null 1189ef36b3f7SMark Johnstonterminator. 1190ef36b3f7SMark JohnstonOffsets that refer to something in this section should refer to the first byte 1191ef36b3f7SMark Johnstonwhich begins a string. 1192ef36b3f7SMark JohnstonBeyond the first byte in the section being the null terminator, the order of 1193ef36b3f7SMark Johnstonstrings is unimportant. 11947421ff07SMark Johnston.Ss Data Encoding and ELF Considerations 119538d120bcSMark Johnston.Nm 119638d120bcSMark Johnstondata is generally included in ELF objects which specify information to 1197ef36b3f7SMark Johnstonidentify the architecture and endianness of the file. 1198ef36b3f7SMark JohnstonA 119938d120bcSMark Johnston.Nm 1200ef36b3f7SMark Johnstoncontainer inside such an object must match the endianness of the ELF object. 1201ef36b3f7SMark JohnstonAside from the question of the endian encoding of data, there should be no other 1202ef36b3f7SMark Johnstondifferences between architectures. 1203ef36b3f7SMark JohnstonWhile many of the types in this document refer to non-fixed size C integral 1204ef36b3f7SMark Johnstontypes, they are equivalent in the models 120538d120bcSMark Johnston.Sy ILP32 120638d120bcSMark Johnstonand 120738d120bcSMark Johnston.Sy LP64 . 120838d120bcSMark JohnstonIf any other model is being used with 120938d120bcSMark Johnston.Nm 121038d120bcSMark Johnstondata that has different sizes, then it must not use the model's sizes for 121138d120bcSMark Johnstonthose integral types and instead use the fixed size equivalents based on an 121238d120bcSMark Johnston.Sy ILP32 121338d120bcSMark Johnstonenvironment. 121438d120bcSMark Johnston.Lp 121538d120bcSMark JohnstonWhen placing a 121638d120bcSMark Johnston.Nm 121738d120bcSMark Johnstoncontainer inside of an ELF object, there are certain conventions that are 121838d120bcSMark Johnstonexpected for the purposes of tooling being able to find the 121938d120bcSMark Johnston.Nm 1220ef36b3f7SMark Johnstondata. 1221ef36b3f7SMark JohnstonIn particular, a given ELF object should only contain a single 122238d120bcSMark Johnston.Nm 1223ef36b3f7SMark Johnstonsection. 1224ef36b3f7SMark JohnstonMultiple containers should be merged together into a single one. 122538d120bcSMark Johnston.Lp 122638d120bcSMark JohnstonThe 122738d120bcSMark Johnston.Nm 1228ef36b3f7SMark Johnstonfile should be included in its own ELF section. 1229ef36b3f7SMark JohnstonThe section's name must be 123038d120bcSMark Johnston.Ql .SUNW_ctf . 123138d120bcSMark JohnstonThe type of the section must be 123238d120bcSMark Johnston.Sy SHT_PROGBITS . 123338d120bcSMark JohnstonThe section should have a link set to the symbol table and its address 123438d120bcSMark Johnstonalignment must be 4. 123538d120bcSMark Johnston.Sh SEE ALSO 1236*994297b0SMark Johnston.Xr ctfconvert 1 , 1237*994297b0SMark Johnston.Xr ctfdump 1 , 1238*994297b0SMark Johnston.Xr ctfmerge 1 , 123938d120bcSMark Johnston.Xr dtrace 1 , 124038d120bcSMark Johnston.Xr elf 3 , 124138d120bcSMark Johnston.Xr gelf 3 , 124238d120bcSMark Johnston.Xr a.out 5 , 12437421ff07SMark Johnston.Xr elf 5 , 12447421ff07SMark Johnston.Xr arch 7 1245