1bbf21555SRichard Lowe.\" 2bbf21555SRichard Lowe.\" This file and its contents are supplied under the terms of the 3bbf21555SRichard Lowe.\" Common Development and Distribution License ("CDDL"), version 1.0. 4bbf21555SRichard Lowe.\" You may only use this file in accordance with the terms of version 5bbf21555SRichard Lowe.\" 1.0 of the CDDL. 6bbf21555SRichard Lowe.\" 7bbf21555SRichard Lowe.\" A full copy of the text of the CDDL should have accompanied this 8bbf21555SRichard Lowe.\" source. A copy of the CDDL is also available via the Internet at 9bbf21555SRichard Lowe.\" http://www.illumos.org/license/CDDL. 10bbf21555SRichard Lowe.\" 11bbf21555SRichard Lowe.\" 12bbf21555SRichard Lowe.\" Copyright (c) 2014 Joyent, Inc. 13bbf21555SRichard Lowe.\" 14*11994f6fSRobert Mustacchi.Dd December 2, 2023 15bbf21555SRichard Lowe.Dt CTF 5 16bbf21555SRichard Lowe.Os 17bbf21555SRichard Lowe.Sh NAME 18bbf21555SRichard Lowe.Nm ctf 19bbf21555SRichard Lowe.Nd Compact C Type Format 20bbf21555SRichard Lowe.Sh SYNOPSIS 21bbf21555SRichard Lowe.In sys/ctf.h 22bbf21555SRichard Lowe.Sh DESCRIPTION 23bbf21555SRichard Lowe.Nm 24bbf21555SRichard Loweis designed to be a compact representation of the C programming 25bbf21555SRichard Lowelanguage's type information focused on serving the needs of dynamic 26bbf21555SRichard Lowetracing, debuggers, and other in-situ and post-mortem introspection 27bbf21555SRichard Lowetools. 28bbf21555SRichard Lowe.Nm 29bbf21555SRichard Lowedata is generally included in 30bbf21555SRichard Lowe.Sy ELF 31bbf21555SRichard Loweobjects and is tagged as 32bbf21555SRichard Lowe.Sy SHT_PROGBITS 33bbf21555SRichard Loweto ensure that the data is accessible in a running process and in subsequent 34bbf21555SRichard Lowecore dumps, if generated. 35bbf21555SRichard Lowe.Lp 36bbf21555SRichard LoweThe 37bbf21555SRichard Lowe.Nm 38bbf21555SRichard Lowedata contained in each file has information about the layout and 39bbf21555SRichard Lowesizes of C types, including intrinsic types, enumerations, structures, 40bbf21555SRichard Lowetypedefs, and unions, that are used by the corresponding 41bbf21555SRichard Lowe.Sy ELF 42bbf21555SRichard Loweobject. 43bbf21555SRichard LoweThe 44bbf21555SRichard Lowe.Nm 45bbf21555SRichard Lowedata may also include information about the types of global objects and 46bbf21555SRichard Lowethe return type and arguments of functions in the symbol table. 47bbf21555SRichard Lowe.Lp 48bbf21555SRichard LoweBecause a 49bbf21555SRichard Lowe.Nm 50bbf21555SRichard Lowefile is often embedded inside a file, rather than being a standalone 51bbf21555SRichard Lowefile itself, it may also be referred to as a 52bbf21555SRichard Lowe.Nm 53bbf21555SRichard Lowe.Sy container . 54bbf21555SRichard Lowe.Lp 55bbf21555SRichard LoweOn illumos systems, 56bbf21555SRichard Lowe.Nm 57bbf21555SRichard Lowedata is consumed by multiple programs. 58bbf21555SRichard LoweIt can be used by the modular debugger, 59bbf21555SRichard Lowe.Xr mdb 1 , 60bbf21555SRichard Loweas well as by 61bbf21555SRichard Lowe.Xr dtrace 8 . 62bbf21555SRichard LoweProgrammatic access to 63bbf21555SRichard Lowe.Nm 64bbf21555SRichard Lowedata can be obtained through 65bbf21555SRichard Lowe.Xr libctf 3LIB . 66bbf21555SRichard Lowe.Lp 67bbf21555SRichard LoweThe 68bbf21555SRichard Lowe.Nm 69bbf21555SRichard Lowefile format is broken down into seven different sections. 70bbf21555SRichard LoweThe first section is the 71bbf21555SRichard Lowe.Sy preamble 72bbf21555SRichard Loweand 73bbf21555SRichard Lowe.Sy header , 74bbf21555SRichard Lowewhich describes the version of the 75bbf21555SRichard Lowe.Nm 76bbf21555SRichard Lowefile, links it has to other 77bbf21555SRichard Lowe.Nm 78bbf21555SRichard Lowefiles, and the sizes of the other sections. 79bbf21555SRichard LoweThe next section is the 80bbf21555SRichard Lowe.Sy label 81bbf21555SRichard Lowesection, 82bbf21555SRichard Lowewhich provides a way of identifying similar groups of 83bbf21555SRichard Lowe.Nm 84bbf21555SRichard Lowedata across multiple files. 85bbf21555SRichard LoweThis is followed by the 86bbf21555SRichard Lowe.Sy object 87bbf21555SRichard Loweinformation section, which describes the type of global 88bbf21555SRichard Lowesymbols. 89bbf21555SRichard LoweThe subsequent section is the 90bbf21555SRichard Lowe.Sy function 91bbf21555SRichard Loweinformation section, which describes the return 92bbf21555SRichard Lowetypes and arguments of functions. 93bbf21555SRichard LoweThe next section is the 94bbf21555SRichard Lowe.Sy type 95bbf21555SRichard Loweinformation section, which describes 96bbf21555SRichard Lowethe format and layout of the C types themselves, and finally the last 97bbf21555SRichard Lowesection is the 98bbf21555SRichard Lowe.Sy string 99bbf21555SRichard Lowesection, which contains the names of types, enumerations, members, and 100bbf21555SRichard Lowelabels. 101bbf21555SRichard Lowe.Lp 102bbf21555SRichard LoweWhile strictly speaking, only the 103bbf21555SRichard Lowe.Sy preamble 104bbf21555SRichard Loweand 105bbf21555SRichard Lowe.Sy header 106bbf21555SRichard Loweare required, to be actually useful, both the type and string 107bbf21555SRichard Lowesections are necessary. 108bbf21555SRichard Lowe.Lp 109bbf21555SRichard LoweA 110bbf21555SRichard Lowe.Nm 111bbf21555SRichard Lowefile may contain all of the type information that it requires, or it 112bbf21555SRichard Lowemay optionally refer to another 113bbf21555SRichard Lowe.Nm 114bbf21555SRichard Lowefile which holds the remaining types. 115bbf21555SRichard LoweWhen a 116bbf21555SRichard Lowe.Nm 117bbf21555SRichard Lowefile refers to another file, it is called the 118bbf21555SRichard Lowe.Sy child 119bbf21555SRichard Loweand the file it refers to is called the 120bbf21555SRichard Lowe.Sy parent . 121bbf21555SRichard LoweA given file may only refer to one parent. 122bbf21555SRichard LoweThis process is called 123bbf21555SRichard Lowe.Em uniquification 124bbf21555SRichard Lowebecause it ensures each child only has type information that is 125bbf21555SRichard Loweunique to it. 126bbf21555SRichard LoweA common example of this is that most kernel modules in illumos are uniquified 127bbf21555SRichard Loweagainst the kernel module 128bbf21555SRichard Lowe.Sy genunix 129bbf21555SRichard Loweand the type information that comes from the 130bbf21555SRichard Lowe.Sy IP 131bbf21555SRichard Lowemodule. 132bbf21555SRichard LoweThis means that a module only has types that are unique to itself and the most 133bbf21555SRichard Lowecommon types in the kernel are not duplicated. 134bbf21555SRichard Lowe.Sh FILE FORMAT 135bbf21555SRichard LoweThis documents version 136bbf21555SRichard Lowe.Em two 137bbf21555SRichard Loweof the 138bbf21555SRichard Lowe.Nm 139bbf21555SRichard Lowefile format. 140bbf21555SRichard LoweAll applications and tools currently produce and operate on this version. 141bbf21555SRichard Lowe.Lp 142bbf21555SRichard LoweThe file format can be summarized with the following image, the 143bbf21555SRichard Lowefollowing sections will cover this in more detail. 144bbf21555SRichard Lowe.Bd -literal 145bbf21555SRichard Lowe 146bbf21555SRichard Lowe +-------------+ 0t0 147bbf21555SRichard Lowe+--------| Preamble | 148bbf21555SRichard Lowe| +-------------+ 0t4 149bbf21555SRichard Lowe|+-------| Header | 150bbf21555SRichard Lowe|| +-------------+ 0t36 + cth_lbloff 151bbf21555SRichard Lowe||+------| Labels | 152bbf21555SRichard Lowe||| +-------------+ 0t36 + cth_objtoff 153bbf21555SRichard Lowe|||+-----| Objects | 154bbf21555SRichard Lowe|||| +-------------+ 0t36 + cth_funcoff 155bbf21555SRichard Lowe||||+----| Functions | 156bbf21555SRichard Lowe||||| +-------------+ 0t36 + cth_typeoff 157bbf21555SRichard Lowe|||||+---| Types | 158bbf21555SRichard Lowe|||||| +-------------+ 0t36 + cth_stroff 159bbf21555SRichard Lowe||||||+--| Strings | 160bbf21555SRichard Lowe||||||| +-------------+ 0t36 + cth_stroff + cth_strlen 161bbf21555SRichard Lowe||||||| 162bbf21555SRichard Lowe||||||| 163bbf21555SRichard Lowe||||||| 164bbf21555SRichard Lowe||||||| +-- magic - vers flags 165bbf21555SRichard Lowe||||||| | | | | 166bbf21555SRichard Lowe||||||| +------+------+------+------+ 167bbf21555SRichard Lowe+---------| 0xcf | 0xf1 | 0x02 | 0x00 | 168bbf21555SRichard Lowe |||||| +------+------+------+------+ 169bbf21555SRichard Lowe |||||| 0 1 2 3 4 170bbf21555SRichard Lowe |||||| 171bbf21555SRichard Lowe |||||| + parent label + objects 172bbf21555SRichard Lowe |||||| | + parent name | + functions + strings 173bbf21555SRichard Lowe |||||| | | + label | | + types | + strlen 174bbf21555SRichard Lowe |||||| | | | | | | | | 175bbf21555SRichard Lowe |||||| +------+------+------+------+------+-------+-------+-------+ 176bbf21555SRichard Lowe +--------| 0x00 | 0x00 | 0x00 | 0x08 | 0x36 | 0x110 | 0x5f4 | 0x611 | 177bbf21555SRichard Lowe ||||| +------+------+------+------+------+-------+-------+-------+ 178bbf21555SRichard Lowe ||||| 0x04 0x08 0x0c 0x10 0x14 0x18 0x1c 0x20 0x24 179bbf21555SRichard Lowe ||||| 180bbf21555SRichard Lowe ||||| + Label name 181bbf21555SRichard Lowe ||||| | + Label type 182bbf21555SRichard Lowe ||||| | | + Next label 183bbf21555SRichard Lowe ||||| | | | 184bbf21555SRichard Lowe ||||| +-------+------+-----+ 185bbf21555SRichard Lowe +-----------| 0x01 | 0x42 | ... | 186bbf21555SRichard Lowe |||| +-------+------+-----+ 187bbf21555SRichard Lowe |||| cth_lbloff +0x4 +0x8 cth_objtoff 188bbf21555SRichard Lowe |||| 189bbf21555SRichard Lowe |||| 190bbf21555SRichard Lowe |||| Symidx 0t15 0t43 0t44 191bbf21555SRichard Lowe |||| +------+------+------+-----+ 192bbf21555SRichard Lowe +----------| 0x00 | 0x42 | 0x36 | ... | 193bbf21555SRichard Lowe ||| +------+------+------+-----+ 194bbf21555SRichard Lowe ||| cth_objtoff +0x2 +0x4 +0x6 cth_funcoff 195bbf21555SRichard Lowe ||| 196bbf21555SRichard Lowe ||| + CTF_TYPE_INFO + CTF_TYPE_INFO 197bbf21555SRichard Lowe ||| | + Return type | 198bbf21555SRichard Lowe ||| | | + arg0 | 199bbf21555SRichard Lowe ||| +--------+------+------+-----+ 200bbf21555SRichard Lowe +---------| 0x2c10 | 0x08 | 0x0c | ... | 201bbf21555SRichard Lowe || +--------+------+------+-----+ 202bbf21555SRichard Lowe || cth_funcff +0x2 +0x4 +0x6 cth_typeoff 203bbf21555SRichard Lowe || 204bbf21555SRichard Lowe || + ctf_stype_t for type 1 205bbf21555SRichard Lowe || | integer + integer encoding 206bbf21555SRichard Lowe || | | + ctf_stype_t for type 2 207bbf21555SRichard Lowe || | | | 208bbf21555SRichard Lowe || +--------------------+-----------+-----+ 209bbf21555SRichard Lowe +--------| 0x19 * 0xc01 * 0x0 | 0x1000000 | ... | 210bbf21555SRichard Lowe | +--------------------+-----------+-----+ 211bbf21555SRichard Lowe | cth_typeoff +0x08 +0x0c cth_stroff 212bbf21555SRichard Lowe | 213bbf21555SRichard Lowe | +--- str 0 214bbf21555SRichard Lowe | | +--- str 1 + str 2 215bbf21555SRichard Lowe | | | | 216bbf21555SRichard Lowe | v v v 217bbf21555SRichard Lowe | +----+---+---+---+----+---+---+---+---+---+----+ 218*11994f6fSRobert Mustacchi +---| \e0 | i | n | t | \e0 | f | o | o | _ | t | \e0 | 219bbf21555SRichard Lowe +----+---+---+---+----+---+---+---+---+---+----+ 220bbf21555SRichard Lowe 0 1 2 3 4 5 6 7 8 9 10 11 221bbf21555SRichard Lowe.Ed 222bbf21555SRichard Lowe.Lp 223bbf21555SRichard LoweEvery 224bbf21555SRichard Lowe.Nm 225bbf21555SRichard Lowefile begins with a 226bbf21555SRichard Lowe.Sy preamble , 227bbf21555SRichard Lowefollowed by a 228bbf21555SRichard Lowe.Sy header . 229bbf21555SRichard LoweThe 230bbf21555SRichard Lowe.Sy preamble 231bbf21555SRichard Loweis defined as follows: 232bbf21555SRichard Lowe.Bd -literal 233bbf21555SRichard Lowetypedef struct ctf_preamble { 234bbf21555SRichard Lowe ushort_t ctp_magic; /* magic number (CTF_MAGIC) */ 235bbf21555SRichard Lowe uchar_t ctp_version; /* data format version number (CTF_VERSION) */ 236bbf21555SRichard Lowe uchar_t ctp_flags; /* flags (see below) */ 237bbf21555SRichard Lowe} ctf_preamble_t; 238bbf21555SRichard Lowe.Ed 239bbf21555SRichard Lowe.Pp 240bbf21555SRichard LoweThe 241bbf21555SRichard Lowe.Sy preamble 242bbf21555SRichard Loweis four bytes long and must be four byte aligned. 243bbf21555SRichard LoweThis 244bbf21555SRichard Lowe.Sy preamble 245bbf21555SRichard Lowedefines the version of the 246bbf21555SRichard Lowe.Nm 247bbf21555SRichard Lowefile which defines the format of the rest of the header. 248bbf21555SRichard LoweWhile the header may change in subsequent versions, the preamble will not change 249bbf21555SRichard Loweacross versions, though the interpretation of its flags may change from 250bbf21555SRichard Loweversion to version. 251bbf21555SRichard LoweThe 252bbf21555SRichard Lowe.Em ctp_magic 253bbf21555SRichard Lowemember defines the magic number for the 254bbf21555SRichard Lowe.Nm 255bbf21555SRichard Lowefile format. 256bbf21555SRichard LoweThis must always be 257bbf21555SRichard Lowe.Li 0xcff1 . 258bbf21555SRichard LoweIf another value is encountered, then the file should not be treated as 259bbf21555SRichard Lowea 260bbf21555SRichard Lowe.Nm 261bbf21555SRichard Lowefile. 262bbf21555SRichard LoweThe 263bbf21555SRichard Lowe.Em ctp_version 264bbf21555SRichard Lowemember defines the version of the 265bbf21555SRichard Lowe.Nm 266bbf21555SRichard Lowefile. 267bbf21555SRichard LoweThe current version is 268bbf21555SRichard Lowe.Li 2 . 269bbf21555SRichard LoweIt is possible to encounter an unsupported version. 270bbf21555SRichard LoweIn that case, software should not try to parse the format, as it may have 271bbf21555SRichard Lowechanged. 272bbf21555SRichard LoweFinally, the 273bbf21555SRichard Lowe.Em ctp_flags 274bbf21555SRichard Lowemember describes aspects of the file which modify its interpretation. 275bbf21555SRichard LoweThe following flags are currently defined: 276bbf21555SRichard Lowe.Bd -literal 277bbf21555SRichard Lowe#define CTF_F_COMPRESS 0x01 278bbf21555SRichard Lowe.Ed 279bbf21555SRichard Lowe.Pp 280bbf21555SRichard LoweThe flag 281bbf21555SRichard Lowe.Sy CTF_F_COMPRESS 282bbf21555SRichard Loweindicates that the body of the 283bbf21555SRichard Lowe.Nm 284bbf21555SRichard Lowefile, all the data following the 285bbf21555SRichard Lowe.Sy header , 286bbf21555SRichard Lowehas been compressed through the 287bbf21555SRichard Lowe.Sy zlib 288bbf21555SRichard Lowelibrary and its 289bbf21555SRichard Lowe.Sy deflate 290bbf21555SRichard Lowealgorithm. 291bbf21555SRichard LoweIf this flag is not present, then the body has not been compressed and no 292bbf21555SRichard Lowespecial action is needed to interpret it. 293bbf21555SRichard LoweAll offsets into the data as described by 294bbf21555SRichard Lowe.Sy header , 295bbf21555SRichard Lowealways refer to the 296bbf21555SRichard Lowe.Sy uncompressed 297bbf21555SRichard Lowedata. 298bbf21555SRichard Lowe.Lp 299bbf21555SRichard LoweIn version two of the 300bbf21555SRichard Lowe.Nm 301bbf21555SRichard Lowefile format, the 302bbf21555SRichard Lowe.Sy header 303bbf21555SRichard Lowedenotes whether whether or not this 304bbf21555SRichard Lowe.Nm 305bbf21555SRichard Lowefile is the child of another 306bbf21555SRichard Lowe.Nm 307bbf21555SRichard Lowefile and also indicates the size of the remaining sections. 308bbf21555SRichard LoweThe structure for the 309bbf21555SRichard Lowe.Sy header , 310bbf21555SRichard Lowelogically contains a copy of the 311bbf21555SRichard Lowe.Sy preamble 312bbf21555SRichard Loweand the two have a combined size of 36 bytes. 313bbf21555SRichard Lowe.Bd -literal 314bbf21555SRichard Lowetypedef struct ctf_header { 315bbf21555SRichard Lowe ctf_preamble_t cth_preamble; 316bbf21555SRichard Lowe uint_t cth_parlabel; /* ref to name of parent lbl uniq'd against */ 317bbf21555SRichard Lowe uint_t cth_parname; /* ref to basename of parent */ 318bbf21555SRichard Lowe uint_t cth_lbloff; /* offset of label section */ 319bbf21555SRichard Lowe uint_t cth_objtoff; /* offset of object section */ 320bbf21555SRichard Lowe uint_t cth_funcoff; /* offset of function section */ 321bbf21555SRichard Lowe uint_t cth_typeoff; /* offset of type section */ 322bbf21555SRichard Lowe uint_t cth_stroff; /* offset of string section */ 323bbf21555SRichard Lowe uint_t cth_strlen; /* length of string section in bytes */ 324bbf21555SRichard Lowe} ctf_header_t; 325bbf21555SRichard Lowe.Ed 326bbf21555SRichard Lowe.Pp 327bbf21555SRichard LoweAfter the 328bbf21555SRichard Lowe.Sy preamble , 329bbf21555SRichard Lowethe next two members 330bbf21555SRichard Lowe.Em cth_parlablel 331bbf21555SRichard Loweand 332bbf21555SRichard Lowe.Em cth_parname , 333bbf21555SRichard Loweare used to identify the parent. 334bbf21555SRichard LoweThe value of both members are offsets into the 335bbf21555SRichard Lowe.Sy string 336bbf21555SRichard Lowesection which point to the start of a null-terminated string. 337bbf21555SRichard LoweFor more information on the encoding of strings, see the subsection on 338bbf21555SRichard Lowe.Sx String Identifiers . 339bbf21555SRichard LoweIf the value of either is zero, then there is no entry for that 340bbf21555SRichard Lowemember. 341bbf21555SRichard LoweIf the member 342bbf21555SRichard Lowe.Em cth_parlabel 343bbf21555SRichard Loweis set, then the 344bbf21555SRichard Lowe.Em ctf_parname 345bbf21555SRichard Lowemember must be set, otherwise it will not be possible to find the 346bbf21555SRichard Loweparent. 347bbf21555SRichard LoweIf 348bbf21555SRichard Lowe.Em ctf_parname 349bbf21555SRichard Loweis set, it is not necessary to define 350bbf21555SRichard Lowe.Em cth_parlabel , 351bbf21555SRichard Loweas the parent may not have a label. 352bbf21555SRichard LoweFor more information on labels and their interpretation, see 353bbf21555SRichard Lowe.Sx The Label Section . 354bbf21555SRichard Lowe.Lp 355bbf21555SRichard LoweThe remaining members (excepting 356bbf21555SRichard Lowe.Em cth_strlen ) 357bbf21555SRichard Lowedescribe the beginning of the corresponding sections. 358bbf21555SRichard LoweThese offsets are relative to the end of the 359bbf21555SRichard Lowe.Sy header . 360bbf21555SRichard LoweTherefore, something with an offset of 0 is at an offset of thirty-six 361bbf21555SRichard Lowebytes relative to the start of the 362bbf21555SRichard Lowe.Nm 363bbf21555SRichard Lowefile. 364bbf21555SRichard LoweThe difference between members indicates the size of the section itself. 365bbf21555SRichard LoweDifferent offsets have different alignment requirements. 366bbf21555SRichard LoweThe start of the 367bbf21555SRichard Lowe.Em cth_objotoff 368bbf21555SRichard Loweand 369bbf21555SRichard Lowe.Em cth_funcoff 370bbf21555SRichard Lowemust be two byte aligned, while the sections 371bbf21555SRichard Lowe.Em cth_lbloff 372bbf21555SRichard Loweand 373bbf21555SRichard Lowe.Em cth_typeoff 374bbf21555SRichard Lowemust be four-byte aligned. 375bbf21555SRichard LoweThe section 376bbf21555SRichard Lowe.Em cth_stroff 377bbf21555SRichard Lowehas no alignment requirements. 378bbf21555SRichard LoweTo calculate the size of a given section, excepting the 379bbf21555SRichard Lowe.Sy string 380bbf21555SRichard Lowesection, one should subtract the offset of the section from the following one. 381bbf21555SRichard LoweFor example, the size of the 382bbf21555SRichard Lowe.Sy types 383bbf21555SRichard Lowesection can be calculated by subtracting 384bbf21555SRichard Lowe.Em cth_stroff 385bbf21555SRichard Lowefrom 386bbf21555SRichard Lowe.Em cth_typeoff . 387bbf21555SRichard Lowe.Lp 388bbf21555SRichard LoweFinally, the member 389bbf21555SRichard Lowe.Em cth_strlen 390bbf21555SRichard Lowedescribes the length of the string section itself. 391bbf21555SRichard LoweFrom it, you can also calculate the size of the entire 392bbf21555SRichard Lowe.Nm 393bbf21555SRichard Lowefile by adding together the size of the 394bbf21555SRichard Lowe.Sy ctf_header_t , 395bbf21555SRichard Lowethe offset of the string section in 396bbf21555SRichard Lowe.Em cth_stroff , 397bbf21555SRichard Loweand the size of the string section in 398bbf21555SRichard Lowe.Em cth_srlen . 399bbf21555SRichard Lowe.Ss Type Identifiers 400bbf21555SRichard LoweThrough the 401bbf21555SRichard Lowe.Nm ctf 402bbf21555SRichard Lowedata, types are referred to by identifiers. 403bbf21555SRichard LoweA given 404bbf21555SRichard Lowe.Nm 405bbf21555SRichard Lowefile supports up to 32767 (0x7fff) types. 406bbf21555SRichard LoweThe first valid type identifier is 0x1. 407bbf21555SRichard LoweWhen a given 408bbf21555SRichard Lowe.Nm 409bbf21555SRichard Lowefile is a child, indicated by a non-zero entry for the 410bbf21555SRichard Lowe.Sy header Ns 's 411bbf21555SRichard Lowe.Em cth_parname , 412bbf21555SRichard Lowethen the first valid type identifier is 0x8000 and the last is 0xffff. 413bbf21555SRichard LoweIn this case, type identifiers 0x1 through 0x7fff are references to the 414bbf21555SRichard Loweparent. 415bbf21555SRichard Lowe.Lp 416bbf21555SRichard LoweThe type identifier zero is a sentinel value used to indicate that there 417bbf21555SRichard Loweis no type information available or it is an unknown type. 418bbf21555SRichard Lowe.Lp 419bbf21555SRichard LoweThroughout the file format, the identifier is stored in different sized 420bbf21555SRichard Lowevalues; however, the minimum size to represent a given identifier is a 421bbf21555SRichard Lowe.Sy uint16_t . 422bbf21555SRichard LoweOther consumers of 423bbf21555SRichard Lowe.Nm 424bbf21555SRichard Loweinformation may use larger or opaque identifiers. 425bbf21555SRichard Lowe.Ss String Identifiers 426bbf21555SRichard LoweString identifiers are always encoded as four byte unsigned integers 427bbf21555SRichard Lowewhich are an offset into a string table. 428bbf21555SRichard LoweThe 429bbf21555SRichard Lowe.Nm 430bbf21555SRichard Loweformat supports two different string tables which have an identifier of 431bbf21555SRichard Lowezero or one. 432bbf21555SRichard LoweThis identifier is stored in the high-order bit of the unsigned four byte 433bbf21555SRichard Loweoffset. 434bbf21555SRichard LoweTherefore, the maximum supported offset into one of these tables is 0x7ffffffff. 435bbf21555SRichard Lowe.Lp 436bbf21555SRichard LoweTable identifier zero, always refers to the 437bbf21555SRichard Lowe.Sy string 438bbf21555SRichard Lowesection in the CTF file itself. 439bbf21555SRichard LoweString table identifier one refers to an external string table which is the ELF 440bbf21555SRichard Lowestring table for the ELF symbol table associated with the 441bbf21555SRichard Lowe.Nm 442bbf21555SRichard Lowecontainer. 443bbf21555SRichard Lowe.Ss Type Encoding 444bbf21555SRichard LoweEvery 445bbf21555SRichard Lowe.Nm 446bbf21555SRichard Lowetype begins with metadata encoded into a 447bbf21555SRichard Lowe.Sy uint16_t . 448bbf21555SRichard LoweThis encoded information tells us three different pieces of information: 449bbf21555SRichard Lowe.Bl -bullet -offset indent -compact 450bbf21555SRichard Lowe.It 451bbf21555SRichard LoweThe kind of the type 452bbf21555SRichard Lowe.It 453bbf21555SRichard LoweWhether this type is a root type or not 454bbf21555SRichard Lowe.It 455bbf21555SRichard LoweThe length of the variable data 456bbf21555SRichard Lowe.El 457bbf21555SRichard Lowe.Lp 458bbf21555SRichard LoweThe 16 bits that make up the encoding are broken down such that you have 459bbf21555SRichard Lowefive bits for the kind, one bit for indicating whether or not it is a 460bbf21555SRichard Loweroot type, and 10 bits for the variable length. 461bbf21555SRichard LoweThis is laid out as follows: 462bbf21555SRichard Lowe.Bd -literal -offset indent 463bbf21555SRichard Lowe+--------------------+ 464bbf21555SRichard Lowe| kind | root | vlen | 465bbf21555SRichard Lowe+--------------------+ 466bbf21555SRichard Lowe15 11 10 9 0 467bbf21555SRichard Lowe.Ed 468bbf21555SRichard Lowe.Lp 469bbf21555SRichard LoweThe current version of the file format defines 14 different kinds. 470bbf21555SRichard LoweThe interpretation of these different kinds will be discussed in the section 471bbf21555SRichard Lowe.Sx The Type Section . 472bbf21555SRichard LoweIf a kind is encountered that is not listed below, then it is not a valid 473bbf21555SRichard Lowe.Nm 474bbf21555SRichard Lowefile. 475bbf21555SRichard LoweThe kinds are defined as follows: 476bbf21555SRichard Lowe.Bd -literal -offset indent 477bbf21555SRichard Lowe#define CTF_K_UNKNOWN 0 478bbf21555SRichard Lowe#define CTF_K_INTEGER 1 479bbf21555SRichard Lowe#define CTF_K_FLOAT 2 480bbf21555SRichard Lowe#define CTF_K_POINTER 3 481bbf21555SRichard Lowe#define CTF_K_ARRAY 4 482bbf21555SRichard Lowe#define CTF_K_FUNCTION 5 483bbf21555SRichard Lowe#define CTF_K_STRUCT 6 484bbf21555SRichard Lowe#define CTF_K_UNION 7 485bbf21555SRichard Lowe#define CTF_K_ENUM 8 486bbf21555SRichard Lowe#define CTF_K_FORWARD 9 487bbf21555SRichard Lowe#define CTF_K_TYPEDEF 10 488bbf21555SRichard Lowe#define CTF_K_VOLATILE 11 489bbf21555SRichard Lowe#define CTF_K_CONST 12 490bbf21555SRichard Lowe#define CTF_K_RESTRICT 13 491bbf21555SRichard Lowe.Ed 492bbf21555SRichard Lowe.Lp 493bbf21555SRichard LowePrograms directly reference many types; however, other types are referenced 494bbf21555SRichard Loweindirectly because they are part of some other structure. 495bbf21555SRichard LoweThese types that are referenced directly and used are called 496bbf21555SRichard Lowe.Sy root 497bbf21555SRichard Lowetypes. 498bbf21555SRichard LoweOther types may be used indirectly, for example, a program may reference 499bbf21555SRichard Lowea structure directly, but not one of its members which has a type. 500bbf21555SRichard LoweThat type is not considered a 501bbf21555SRichard Lowe.Sy root 502bbf21555SRichard Lowetype. 503bbf21555SRichard LoweIf a type is a 504bbf21555SRichard Lowe.Sy root 505bbf21555SRichard Lowetype, then it will have bit 10 set. 506bbf21555SRichard Lowe.Lp 507bbf21555SRichard LoweThe variable length section is specific to each kind and is discussed in the 508bbf21555SRichard Lowesection 509bbf21555SRichard Lowe.Sx The Type Section . 510bbf21555SRichard Lowe.Lp 511bbf21555SRichard LoweThe following macros are useful for constructing and deconstructing the encoded 512bbf21555SRichard Lowetype information: 513bbf21555SRichard Lowe.Bd -literal -offset indent 514bbf21555SRichard Lowe 515bbf21555SRichard Lowe#define CTF_MAX_VLEN 0x3ff 516bbf21555SRichard Lowe#define CTF_INFO_KIND(info) (((info) & 0xf800) >> 11) 517bbf21555SRichard Lowe#define CTF_INFO_ISROOT(info) (((info) & 0x0400) >> 10) 518bbf21555SRichard Lowe#define CTF_INFO_VLEN(info) (((info) & CTF_MAX_VLEN)) 519bbf21555SRichard Lowe 520*11994f6fSRobert Mustacchi#define CTF_TYPE_INFO(kind, isroot, vlen) \e 521bbf21555SRichard Lowe (((kind) << 11) | (((isroot) ? 1 : 0) << 10) | ((vlen) & CTF_MAX_VLEN)) 522bbf21555SRichard Lowe.Ed 523bbf21555SRichard Lowe.Ss The Label Section 524bbf21555SRichard LoweWhen consuming 525bbf21555SRichard Lowe.Nm 526bbf21555SRichard Lowedata, it is often useful to know whether two different 527bbf21555SRichard Lowe.Nm 528bbf21555SRichard Lowecontainers come from the same source base and version. 529bbf21555SRichard LoweFor example, when building illumos, there are many kernel modules that are built 530bbf21555SRichard Loweagainst a single collection of source code. 531bbf21555SRichard LoweA label is encoded into the 532bbf21555SRichard Lowe.Nm 533bbf21555SRichard Lowefiles that corresponds with the particular build. 534bbf21555SRichard LoweThis ensures that if files on the system were to become mixed up from multiple 535bbf21555SRichard Lowereleases, that they are not used together by tools, particularly when a child 536bbf21555SRichard Loweneeds to refer to a type in the parent. 537bbf21555SRichard LoweBecause they are linked used the type identifiers, if the wrong parent is used 538bbf21555SRichard Lowethen the wrong type will be encountered. 539bbf21555SRichard Lowe.Lp 540bbf21555SRichard LoweEach label is encoded in the file format using the following eight byte 541bbf21555SRichard Lowestructure: 542bbf21555SRichard Lowe.Bd -literal 543bbf21555SRichard Lowetypedef struct ctf_lblent { 544bbf21555SRichard Lowe uint_t ctl_label; /* ref to name of label */ 545bbf21555SRichard Lowe uint_t ctl_typeidx; /* last type associated with this label */ 546bbf21555SRichard Lowe} ctf_lblent_t; 547bbf21555SRichard Lowe.Ed 548bbf21555SRichard Lowe.Lp 549bbf21555SRichard LoweEach label has two different components, a name and a type identifier. 550bbf21555SRichard LoweThe name is encoded in the 551bbf21555SRichard Lowe.Em ctl_label 552bbf21555SRichard Lowemember which is in the format defined in the section 553bbf21555SRichard Lowe.Sx String Identifiers . 554bbf21555SRichard LoweGenerally, the names of all labels are found in the internal string 555bbf21555SRichard Lowesection. 556bbf21555SRichard Lowe.Lp 557bbf21555SRichard LoweThe type identifier encoded in the member 558bbf21555SRichard Lowe.Em ctl_typeidx 559bbf21555SRichard Lowerefers to the last type identifier that a label refers to in the current 560bbf21555SRichard Lowefile. 561bbf21555SRichard LoweLabels only refer to types in the current file, if the 562bbf21555SRichard Lowe.Nm 563bbf21555SRichard Lowefile is a child, then it will have the same label as its parent; 564bbf21555SRichard Lowehowever, its label will only refer to its types, not its parents. 565bbf21555SRichard Lowe.Lp 566bbf21555SRichard LoweIt is also possible, though rather uncommon, for a 567bbf21555SRichard Lowe.Nm 568bbf21555SRichard Lowefile to have multiple labels. 569bbf21555SRichard LoweLabels are placed one after another, every eight bytes. 570bbf21555SRichard LoweWhen multiple labels are present, types may only belong to a single label. 571bbf21555SRichard Lowe.Ss The Object Section 572bbf21555SRichard LoweThe object section provides a mapping from ELF symbols of type 573bbf21555SRichard Lowe.Sy STT_OBJECT 574bbf21555SRichard Lowein the symbol table to a type identifier. 575bbf21555SRichard LoweEvery entry in this section is a 576bbf21555SRichard Lowe.Sy uint16_t 577bbf21555SRichard Lowewhich contains a type identifier as described in the section 578bbf21555SRichard Lowe.Sx Type Identifiers . 579bbf21555SRichard LoweIf there is no information for an object, then the type identifier 0x0 580bbf21555SRichard Loweis stored for that entry. 581bbf21555SRichard Lowe.Lp 582bbf21555SRichard LoweTo walk the object section, you need to have a corresponding 583bbf21555SRichard Lowe.Sy symbol table 584bbf21555SRichard Lowein the ELF object that contains the 585bbf21555SRichard Lowe.Nm 586bbf21555SRichard Lowedata. 587bbf21555SRichard LoweNot every object is included in this section. 588bbf21555SRichard LoweSpecifically, when walking the symbol table. 589bbf21555SRichard LoweAn entry is skipped if it matches any of the following conditions: 590bbf21555SRichard Lowe.Lp 591bbf21555SRichard Lowe.Bl -bullet -offset indent -compact 592bbf21555SRichard Lowe.It 593bbf21555SRichard LoweThe symbol type is not 594bbf21555SRichard Lowe.Sy STT_OBJECT 595bbf21555SRichard Lowe.It 596bbf21555SRichard LoweThe symbol's section index is 597bbf21555SRichard Lowe.Sy SHN_UNDEF 598bbf21555SRichard Lowe.It 599bbf21555SRichard LoweThe symbol's name offset is zero 600bbf21555SRichard Lowe.It 601bbf21555SRichard LoweThe symbol's section index is 602bbf21555SRichard Lowe.Sy SHN_ABS 603bbf21555SRichard Loweand the value of the symbol is zero. 604bbf21555SRichard Lowe.It 605bbf21555SRichard LoweThe symbol's name is 606bbf21555SRichard Lowe.Li _START_ 607bbf21555SRichard Loweor 608bbf21555SRichard Lowe.Li _END_ . 609bbf21555SRichard LoweThese are skipped because they are used for scoping local symbols in 610bbf21555SRichard LoweELF. 611bbf21555SRichard Lowe.El 612bbf21555SRichard Lowe.Lp 613bbf21555SRichard LoweThe following sample code shows an example of iterating the object 614bbf21555SRichard Lowesection and skipping the correct symbols: 615bbf21555SRichard Lowe.Bd -literal 616bbf21555SRichard Lowe#include <gelf.h> 617bbf21555SRichard Lowe#include <stdio.h> 618bbf21555SRichard Lowe 619bbf21555SRichard Lowe/* 620bbf21555SRichard Lowe * Given the start of the object section in the CTF file, the number of symbols, 621bbf21555SRichard Lowe * and the ELF Data sections for the symbol table and the string table, this 622bbf21555SRichard Lowe * prints the type identifiers that correspond to objects. Note, a more robust 623bbf21555SRichard Lowe * implementation should ensure that they don't walk beyond the end of the CTF 624bbf21555SRichard Lowe * object section. 625bbf21555SRichard Lowe */ 626bbf21555SRichard Lowestatic int 627bbf21555SRichard Lowewalk_symbols(uint16_t *objtoff, Elf_Data *symdata, Elf_Data *strdata, 628bbf21555SRichard Lowe long nsyms) 629bbf21555SRichard Lowe{ 630bbf21555SRichard Lowe long i; 631bbf21555SRichard Lowe uintptr_t strbase = strdata->d_buf; 632bbf21555SRichard Lowe 633bbf21555SRichard Lowe for (i = 1; i < nsyms; i++, objftoff++) { 634bbf21555SRichard Lowe const char *name; 635bbf21555SRichard Lowe GElf_Sym sym; 636bbf21555SRichard Lowe 637bbf21555SRichard Lowe if (gelf_getsym(symdata, i, &sym) == NULL) 638bbf21555SRichard Lowe return (1); 639bbf21555SRichard Lowe 640bbf21555SRichard Lowe if (GELF_ST_TYPE(sym.st_info) != STT_OBJECT) 641bbf21555SRichard Lowe continue; 642bbf21555SRichard Lowe if (sym.st_shndx == SHN_UNDEF || sym.st_name == 0) 643bbf21555SRichard Lowe continue; 644bbf21555SRichard Lowe if (sym.st_shndx == SHN_ABS && sym.st_value == 0) 645bbf21555SRichard Lowe continue; 646bbf21555SRichard Lowe name = (const char *)(strbase + sym.st_name); 647bbf21555SRichard Lowe if (strcmp(name, "_START_") == 0 || strcmp(name, "_END_") == 0) 648bbf21555SRichard Lowe continue; 649bbf21555SRichard Lowe 650bbf21555SRichard Lowe (void) printf("Symbol %d has type %d\n", i, *objtoff); 651bbf21555SRichard Lowe } 652bbf21555SRichard Lowe 653bbf21555SRichard Lowe return (0); 654bbf21555SRichard Lowe} 655bbf21555SRichard Lowe.Ed 656bbf21555SRichard Lowe.Ss The Function Section 657bbf21555SRichard LoweThe function section of the 658bbf21555SRichard Lowe.Nm 659bbf21555SRichard Lowefile encodes the types of both the function's arguments and the function's 660bbf21555SRichard Lowereturn type. 661bbf21555SRichard LoweSimilar to 662bbf21555SRichard Lowe.Sx The Object Section , 663bbf21555SRichard Lowethe function section encodes information for all symbols of type 664bbf21555SRichard Lowe.Sy STT_FUNCTION , 665bbf21555SRichard Loweexcepting those that fit specific criteria. 666bbf21555SRichard LoweUnlike with objects, because functions have a variable number of arguments, they 667bbf21555SRichard Lowestart with a type encoding as defined in 668bbf21555SRichard Lowe.Sx Type Encoding , 669bbf21555SRichard Lowewhich is the size of a 670bbf21555SRichard Lowe.Sy uint16_t . 671bbf21555SRichard LoweFor functions which have no type information available, they are encoded as 672bbf21555SRichard Lowe.Li CTF_TYPE_INFO(CTF_K_UNKNOWN, 0, 0) . 673bbf21555SRichard LoweFunctions with arguments are encoded differently. 674bbf21555SRichard LoweHere, the variable length is turned into the number of arguments in the 675bbf21555SRichard Lowefunction. 676bbf21555SRichard LoweIf a function is a 677bbf21555SRichard Lowe.Sy varargs 678bbf21555SRichard Lowetype function, then the number of arguments is increased by one. 679bbf21555SRichard LoweFunctions with type information are encoded as: 680bbf21555SRichard Lowe.Li CTF_TYPE_INFO(CTF_K_FUNCTION, 0, nargs) . 681bbf21555SRichard Lowe.Lp 682bbf21555SRichard LoweFor functions that have no type information, nothing else is encoded, and the 683bbf21555SRichard Lowenext function is encoded. 684bbf21555SRichard LoweFor functions with type information, the next 685bbf21555SRichard Lowe.Sy uint16_t 686bbf21555SRichard Loweis encoded with the type identifier of the return type of the function. 687bbf21555SRichard LoweIt is followed by each of the type identifiers of the arguments, if any exist, 688bbf21555SRichard Lowein the order that they appear in the function. 689bbf21555SRichard LoweTherefore, argument 0 is the first type identifier and so on. 690bbf21555SRichard LoweWhen a function has a final varargs argument, that is encoded with the type 691bbf21555SRichard Loweidentifier of zero. 692bbf21555SRichard Lowe.Lp 693bbf21555SRichard LoweLike 694bbf21555SRichard Lowe.Sx The Object Section , 695bbf21555SRichard Lowethe function section is encoded in the order of the symbol table. 696bbf21555SRichard LoweIt has similar, but slightly different considerations from objects. 697bbf21555SRichard LoweWhile iterating the symbol table, if any of the following conditions are true, 698bbf21555SRichard Lowethen the entry is skipped and no corresponding entry is written: 699bbf21555SRichard Lowe.Lp 700bbf21555SRichard Lowe.Bl -bullet -offset indent -compact 701bbf21555SRichard Lowe.It 702bbf21555SRichard LoweThe symbol type is not 703bbf21555SRichard Lowe.Sy STT_FUNCTION 704bbf21555SRichard Lowe.It 705bbf21555SRichard LoweThe symbol's section index is 706bbf21555SRichard Lowe.Sy SHN_UNDEF 707bbf21555SRichard Lowe.It 708bbf21555SRichard LoweThe symbol's name offset is zero 709bbf21555SRichard Lowe.It 710bbf21555SRichard LoweThe symbol's name is 711bbf21555SRichard Lowe.Li _START_ 712bbf21555SRichard Loweor 713bbf21555SRichard Lowe.Li _END_ . 714bbf21555SRichard LoweThese are skipped because they are used for scoping local symbols in 715bbf21555SRichard LoweELF. 716bbf21555SRichard Lowe.El 717bbf21555SRichard Lowe.Ss The Type Section 718bbf21555SRichard LoweThe type section is the heart of the 719bbf21555SRichard Lowe.Nm 720bbf21555SRichard Lowedata. 721bbf21555SRichard LoweIt encodes all of the information about the types themselves. 722bbf21555SRichard LoweThe base of the type information comes in two forms, a short form and a long 723bbf21555SRichard Loweform, each of which may be followed by a variable number of arguments. 724bbf21555SRichard LoweThe following definitions describe the short and long forms: 725bbf21555SRichard Lowe.Bd -literal 726bbf21555SRichard Lowe#define CTF_MAX_SIZE 0xfffe /* max size of a type in bytes */ 727bbf21555SRichard Lowe#define CTF_LSIZE_SENT 0xffff /* sentinel for ctt_size */ 728bbf21555SRichard Lowe#define CTF_MAX_LSIZE UINT64_MAX 729bbf21555SRichard Lowe 730bbf21555SRichard Lowetypedef struct ctf_stype { 731bbf21555SRichard Lowe uint_t ctt_name; /* reference to name in string table */ 732bbf21555SRichard Lowe ushort_t ctt_info; /* encoded kind, variant length */ 733bbf21555SRichard Lowe union { 734bbf21555SRichard Lowe ushort_t _size; /* size of entire type in bytes */ 735bbf21555SRichard Lowe ushort_t _type; /* reference to another type */ 736bbf21555SRichard Lowe } _u; 737bbf21555SRichard Lowe} ctf_stype_t; 738bbf21555SRichard Lowe 739bbf21555SRichard Lowetypedef struct ctf_type { 740bbf21555SRichard Lowe uint_t ctt_name; /* reference to name in string table */ 741bbf21555SRichard Lowe ushort_t ctt_info; /* encoded kind, variant length */ 742bbf21555SRichard Lowe union { 743bbf21555SRichard Lowe ushort_t _size; /* always CTF_LSIZE_SENT */ 744bbf21555SRichard Lowe ushort_t _type; /* do not use */ 745bbf21555SRichard Lowe } _u; 746bbf21555SRichard Lowe uint_t ctt_lsizehi; /* high 32 bits of type size in bytes */ 747bbf21555SRichard Lowe uint_t ctt_lsizelo; /* low 32 bits of type size in bytes */ 748bbf21555SRichard Lowe} ctf_type_t; 749bbf21555SRichard Lowe 750bbf21555SRichard Lowe#define ctt_size _u._size /* for fundamental types that have a size */ 751bbf21555SRichard Lowe#define ctt_type _u._type /* for types that reference another type */ 752bbf21555SRichard Lowe.Ed 753bbf21555SRichard Lowe.Pp 754bbf21555SRichard LoweType sizes are stored in 755bbf21555SRichard Lowe.Sy bytes . 756bbf21555SRichard LoweThe basic small form uses a 757bbf21555SRichard Lowe.Sy ushort_t 758bbf21555SRichard Loweto store the number of bytes. 759bbf21555SRichard LoweIf the number of bytes in a structure would exceed 0xfffe, then the alternate 760bbf21555SRichard Loweform, the 761bbf21555SRichard Lowe.Sy ctf_type_t , 762bbf21555SRichard Loweis used instead. 763bbf21555SRichard LoweTo indicate that the larger form is being used, the member 764bbf21555SRichard Lowe.Em ctt_size 765bbf21555SRichard Loweis set to value of 766bbf21555SRichard Lowe.Sy CTF_LSIZE_SENT 767bbf21555SRichard Lowe(0xffff). 768bbf21555SRichard LoweIn general, when going through the type section, consumers use the 769bbf21555SRichard Lowe.Sy ctf_type_t 770bbf21555SRichard Lowestructure, but pay attention to the value of the member 771bbf21555SRichard Lowe.Em ctt_size 772bbf21555SRichard Loweto determine whether they should increment their scan by the size of the 773bbf21555SRichard Lowe.Sy ctf_stype_t 774bbf21555SRichard Loweor 775bbf21555SRichard Lowe.Sy ctf_type_t . 776bbf21555SRichard LoweNot all kinds of types use 777bbf21555SRichard Lowe.Sy ctt_size . 778bbf21555SRichard LoweThose which do not, will always use the 779bbf21555SRichard Lowe.Sy ctf_stype_t 780bbf21555SRichard Lowestructure. 781bbf21555SRichard LoweThe individual sections for each kind have more information. 782bbf21555SRichard Lowe.Lp 783bbf21555SRichard LoweTypes are written out in order. 784bbf21555SRichard LoweTherefore the first entry encountered has a type id of 0x1, or 0x8000 if a 785bbf21555SRichard Lowechild. 786bbf21555SRichard LoweThe member 787bbf21555SRichard Lowe.Em ctt_name 788bbf21555SRichard Loweis encoded as described in the section 789bbf21555SRichard Lowe.Sx String Identifiers . 790bbf21555SRichard LoweThe string that it points to is the name of the type. 791bbf21555SRichard LoweIf the identifier points to an empty string (one that consists solely of a null 792bbf21555SRichard Loweterminator) then the type does not have a name, this is common with anonymous 793bbf21555SRichard Lowestructures and unions that only have a typedef to name them, as well as, 794bbf21555SRichard Lowepointers and qualifiers. 795bbf21555SRichard Lowe.Lp 796bbf21555SRichard LoweThe next member, the 797bbf21555SRichard Lowe.Em ctt_info , 798bbf21555SRichard Loweis encoded as described in the section 799bbf21555SRichard Lowe.Sx Type Encoding . 800bbf21555SRichard LoweThe types kind tells us how to interpret the remaining data in the 801bbf21555SRichard Lowe.Sy ctf_type_t 802bbf21555SRichard Loweand any variable length data that may exist. 803bbf21555SRichard LoweThe rest of this section will be broken down into the interpretation of the 804bbf21555SRichard Lowevarious kinds. 805bbf21555SRichard Lowe.Ss Encoding of Integers 806bbf21555SRichard LoweIntegers, which are of type 807bbf21555SRichard Lowe.Sy CTF_K_INTEGER , 808bbf21555SRichard Lowehave no variable length arguments. 809bbf21555SRichard LoweInstead, they are followed by a four byte 810bbf21555SRichard Lowe.Sy uint_t 811bbf21555SRichard Lowewhich describes their encoding. 812bbf21555SRichard LoweAll integers must be encoded with a variable length of zero. 813bbf21555SRichard LoweThe 814bbf21555SRichard Lowe.Em ctt_size 815bbf21555SRichard Lowemember describes the length of the integer in bytes. 816bbf21555SRichard LoweIn general, integer sizes will be rounded up to the closest power of two. 817bbf21555SRichard Lowe.Lp 818bbf21555SRichard LoweThe integer encoding contains three different pieces of information: 819bbf21555SRichard Lowe.Bl -bullet -offset indent -compact 820bbf21555SRichard Lowe.It 821bbf21555SRichard LoweThe encoding of the integer 822bbf21555SRichard Lowe.It 823bbf21555SRichard LoweThe offset in 824bbf21555SRichard Lowe.Sy bits 825bbf21555SRichard Loweof the type 826bbf21555SRichard Lowe.It 827bbf21555SRichard LoweThe size in 828bbf21555SRichard Lowe.Sy bits 829bbf21555SRichard Loweof the type 830bbf21555SRichard Lowe.El 831bbf21555SRichard Lowe.Pp 832bbf21555SRichard LoweThis encoding can be expressed through the following macros: 833bbf21555SRichard Lowe.Bd -literal -offset indent 834bbf21555SRichard Lowe#define CTF_INT_ENCODING(data) (((data) & 0xff000000) >> 24) 835bbf21555SRichard Lowe#define CTF_INT_OFFSET(data) (((data) & 0x00ff0000) >> 16) 836bbf21555SRichard Lowe#define CTF_INT_BITS(data) (((data) & 0x0000ffff)) 837bbf21555SRichard Lowe 838*11994f6fSRobert Mustacchi#define CTF_INT_DATA(encoding, offset, bits) \e 839bbf21555SRichard Lowe (((encoding) << 24) | ((offset) << 16) | (bits)) 840bbf21555SRichard Lowe.Ed 841bbf21555SRichard Lowe.Pp 842bbf21555SRichard LoweThe following flags are defined for the encoding at this time: 843bbf21555SRichard Lowe.Bd -literal -offset indent 844bbf21555SRichard Lowe#define CTF_INT_SIGNED 0x01 845bbf21555SRichard Lowe#define CTF_INT_CHAR 0x02 846bbf21555SRichard Lowe#define CTF_INT_BOOL 0x04 847bbf21555SRichard Lowe#define CTF_INT_VARARGS 0x08 848bbf21555SRichard Lowe.Ed 849bbf21555SRichard Lowe.Lp 850bbf21555SRichard LoweBy default, an integer is considered to be unsigned, unless it has the 851bbf21555SRichard Lowe.Sy CTF_INT_SIGNED 852bbf21555SRichard Loweflag set. 853bbf21555SRichard LoweIf the flag 854bbf21555SRichard Lowe.Sy CTF_INT_CHAR 855bbf21555SRichard Loweis set, that indicates that the integer is of a type that stores character 856bbf21555SRichard Lowedata, for example the intrinsic C type 857bbf21555SRichard Lowe.Sy char 858bbf21555SRichard Lowewould have the 859bbf21555SRichard Lowe.Sy CTF_INT_CHAR 860bbf21555SRichard Loweflag set. 861bbf21555SRichard LoweIf the flag 862bbf21555SRichard Lowe.Sy CTF_INT_BOOL 863bbf21555SRichard Loweis set, that indicates that the integer represents a boolean type. 864bbf21555SRichard LoweFor example, the intrinsic C type 865bbf21555SRichard Lowe.Sy _Bool 866bbf21555SRichard Lowewould have the 867bbf21555SRichard Lowe.Sy CTF_INT_BOOL 868bbf21555SRichard Loweflag set. 869bbf21555SRichard LoweFinally, the flag 870bbf21555SRichard Lowe.Sy CTF_INT_VARARGS 871bbf21555SRichard Loweindicates that the integer is used as part of a variable number of arguments. 872bbf21555SRichard LoweThis encoding is rather uncommon. 873bbf21555SRichard Lowe.Ss Encoding of Floats 874bbf21555SRichard LoweFloats, which are of type 875bbf21555SRichard Lowe.Sy CTF_K_FLOAT , 876bbf21555SRichard Loweare similar to their integer counterparts. 877bbf21555SRichard LoweThey have no variable length arguments and are followed by a four byte encoding 878bbf21555SRichard Lowewhich describes the kind of float that exists. 879bbf21555SRichard LoweThe 880bbf21555SRichard Lowe.Em ctt_size 881bbf21555SRichard Lowemember is the size, in bytes, of the float. 882bbf21555SRichard LoweThe float encoding has three different pieces of information inside of it: 883bbf21555SRichard Lowe.Lp 884bbf21555SRichard Lowe.Bl -bullet -offset indent -compact 885bbf21555SRichard Lowe.It 886bbf21555SRichard LoweThe specific kind of float that exists 887bbf21555SRichard Lowe.It 888bbf21555SRichard LoweThe offset in 889bbf21555SRichard Lowe.Sy bits 890bbf21555SRichard Loweof the float 891bbf21555SRichard Lowe.It 892bbf21555SRichard LoweThe size in 893bbf21555SRichard Lowe.Sy bits 894bbf21555SRichard Loweof the float 895bbf21555SRichard Lowe.El 896bbf21555SRichard Lowe.Lp 897bbf21555SRichard LoweThis encoding can be expressed through the following macros: 898bbf21555SRichard Lowe.Bd -literal -offset indent 899bbf21555SRichard Lowe#define CTF_FP_ENCODING(data) (((data) & 0xff000000) >> 24) 900bbf21555SRichard Lowe#define CTF_FP_OFFSET(data) (((data) & 0x00ff0000) >> 16) 901bbf21555SRichard Lowe#define CTF_FP_BITS(data) (((data) & 0x0000ffff)) 902bbf21555SRichard Lowe 903*11994f6fSRobert Mustacchi#define CTF_FP_DATA(encoding, offset, bits) \e 904bbf21555SRichard Lowe (((encoding) << 24) | ((offset) << 16) | (bits)) 905bbf21555SRichard Lowe.Ed 906bbf21555SRichard Lowe.Lp 907bbf21555SRichard LoweWhere as the encoding for integers was a series of flags, the encoding for 908bbf21555SRichard Lowefloats maps to a specific kind of float. 909bbf21555SRichard LoweIt is not a flag-based value. 910bbf21555SRichard LoweThe kinds of floats correspond to both their size, and the encoding. 911bbf21555SRichard LoweThis covers all of the basic C intrinsic floating point types. 912bbf21555SRichard LoweThe following are the different kinds of floats represented in the encoding: 913bbf21555SRichard Lowe.Bd -literal -offset indent 914bbf21555SRichard Lowe#define CTF_FP_SINGLE 1 /* IEEE 32-bit float encoding */ 915bbf21555SRichard Lowe#define CTF_FP_DOUBLE 2 /* IEEE 64-bit float encoding */ 916bbf21555SRichard Lowe#define CTF_FP_CPLX 3 /* Complex encoding */ 917bbf21555SRichard Lowe#define CTF_FP_DCPLX 4 /* Double complex encoding */ 918bbf21555SRichard Lowe#define CTF_FP_LDCPLX 5 /* Long double complex encoding */ 919bbf21555SRichard Lowe#define CTF_FP_LDOUBLE 6 /* Long double encoding */ 920bbf21555SRichard Lowe#define CTF_FP_INTRVL 7 /* Interval (2x32-bit) encoding */ 921bbf21555SRichard Lowe#define CTF_FP_DINTRVL 8 /* Double interval (2x64-bit) encoding */ 922bbf21555SRichard Lowe#define CTF_FP_LDINTRVL 9 /* Long double interval (2x128-bit) encoding */ 923bbf21555SRichard Lowe#define CTF_FP_IMAGRY 10 /* Imaginary (32-bit) encoding */ 924bbf21555SRichard Lowe#define CTF_FP_DIMAGRY 11 /* Long imaginary (64-bit) encoding */ 925bbf21555SRichard Lowe#define CTF_FP_LDIMAGRY 12 /* Long double imaginary (128-bit) encoding */ 926bbf21555SRichard Lowe.Ed 927bbf21555SRichard Lowe.Ss Encoding of Arrays 928bbf21555SRichard LoweArrays, which are of type 929bbf21555SRichard Lowe.Sy CTF_K_ARRAY , 930bbf21555SRichard Lowehave no variable length arguments. 931bbf21555SRichard LoweThey are followed by a structure which describes the number of elements in the 932bbf21555SRichard Lowearray, the type identifier of the elements in the array, and the type identifier 933bbf21555SRichard Loweof the index of the array. 934bbf21555SRichard LoweWith arrays, the 935bbf21555SRichard Lowe.Em ctt_size 936bbf21555SRichard Lowemember is set to zero. 937bbf21555SRichard LoweThe structure that follows an array is defined as: 938bbf21555SRichard Lowe.Bd -literal 939bbf21555SRichard Lowetypedef struct ctf_array { 940bbf21555SRichard Lowe ushort_t cta_contents; /* reference to type of array contents */ 941bbf21555SRichard Lowe ushort_t cta_index; /* reference to type of array index */ 942bbf21555SRichard Lowe uint_t cta_nelems; /* number of elements */ 943bbf21555SRichard Lowe} ctf_array_t; 944bbf21555SRichard Lowe.Ed 945bbf21555SRichard Lowe.Lp 946bbf21555SRichard LoweThe 947bbf21555SRichard Lowe.Em cta_contents 948bbf21555SRichard Loweand 949bbf21555SRichard Lowe.Em cta_index 950bbf21555SRichard Lowemembers of the 951bbf21555SRichard Lowe.Sy ctf_array_t 952bbf21555SRichard Loweare type identifiers which are encoded as per the section 953bbf21555SRichard Lowe.Sx Type Identifiers . 954bbf21555SRichard LoweThe member 955bbf21555SRichard Lowe.Em cta_nelems 956bbf21555SRichard Loweis a simple four byte unsigned count of the number of elements. 957bbf21555SRichard LoweThis count may be zero when encountering C99's flexible array members. 958bbf21555SRichard Lowe.Ss Encoding of Functions 959bbf21555SRichard LoweFunction types, which are of type 960bbf21555SRichard Lowe.Sy CTF_K_FUNCTION , 961bbf21555SRichard Loweuse the variable length list to be the number of arguments in the function. 962bbf21555SRichard LoweWhen the function has a final member which is a varargs, then the argument count 963bbf21555SRichard Loweis incremented by one to account for the variable argument. 964bbf21555SRichard LoweHere, the 965bbf21555SRichard Lowe.Em ctt_type 966bbf21555SRichard Lowemember is encoded with the type identifier of the return type of the function. 967bbf21555SRichard LoweNote that the 968bbf21555SRichard Lowe.Em ctt_size 969bbf21555SRichard Lowemember is not used here. 970bbf21555SRichard Lowe.Lp 971bbf21555SRichard LoweThe variable argument list contains the type identifiers for the arguments of 972bbf21555SRichard Lowethe function, if any. 973bbf21555SRichard LoweEach one is represented by a 974bbf21555SRichard Lowe.Sy uint16_t 975bbf21555SRichard Loweand encoded according to the 976bbf21555SRichard Lowe.Sx Type Identifiers 977bbf21555SRichard Lowesection. 978bbf21555SRichard LoweIf the function's last argument is of type varargs, then it is also written out, 979bbf21555SRichard Lowebut the type identifier is zero. 980bbf21555SRichard LoweThis is included in the count of the function's arguments. 981bbf21555SRichard Lowe.Ss Encoding of Structures and Unions 982bbf21555SRichard LoweStructures and Unions, which are encoded with 983bbf21555SRichard Lowe.Sy CTF_K_STRUCT 984bbf21555SRichard Loweand 985bbf21555SRichard Lowe.Sy CTF_K_UNION 986bbf21555SRichard Lowerespectively, are very similar constructs in C. 987bbf21555SRichard LoweThe main difference between them is the fact that every member of a structure 988bbf21555SRichard Lowefollows one another, where as in a union, all members share the same memory. 989bbf21555SRichard LoweThey are also very similar in terms of their encoding in 990bbf21555SRichard Lowe.Nm . 991bbf21555SRichard LoweThe variable length argument for structures and unions represents the number of 992bbf21555SRichard Lowemembers that they have. 993bbf21555SRichard LoweThe value of the member 994bbf21555SRichard Lowe.Em ctt_size 995bbf21555SRichard Loweis the size of the structure and union. 996bbf21555SRichard LoweThere are two different structures which are used to encode members in the 997bbf21555SRichard Lowevariable list. 998bbf21555SRichard LoweWhen the size of a structure or union is greater than or equal to the large 999bbf21555SRichard Lowemember threshold, 8192, then a different structure is used to encode the member, 1000bbf21555SRichard Loweall members are encoded using the same structure. 1001bbf21555SRichard LoweThe structure for members is as follows: 1002bbf21555SRichard Lowe.Bd -literal 1003bbf21555SRichard Lowetypedef struct ctf_member { 1004bbf21555SRichard Lowe uint_t ctm_name; /* reference to name in string table */ 1005bbf21555SRichard Lowe ushort_t ctm_type; /* reference to type of member */ 1006bbf21555SRichard Lowe ushort_t ctm_offset; /* offset of this member in bits */ 1007bbf21555SRichard Lowe} ctf_member_t; 1008bbf21555SRichard Lowe 1009bbf21555SRichard Lowetypedef struct ctf_lmember { 1010bbf21555SRichard Lowe uint_t ctlm_name; /* reference to name in string table */ 1011bbf21555SRichard Lowe ushort_t ctlm_type; /* reference to type of member */ 1012bbf21555SRichard Lowe ushort_t ctlm_pad; /* padding */ 1013bbf21555SRichard Lowe uint_t ctlm_offsethi; /* high 32 bits of member offset in bits */ 1014bbf21555SRichard Lowe uint_t ctlm_offsetlo; /* low 32 bits of member offset in bits */ 1015bbf21555SRichard Lowe} ctf_lmember_t; 1016bbf21555SRichard Lowe.Ed 1017bbf21555SRichard Lowe.Lp 1018bbf21555SRichard LoweBoth the 1019bbf21555SRichard Lowe.Em ctm_name 1020bbf21555SRichard Loweand 1021bbf21555SRichard Lowe.Em ctlm_name 1022bbf21555SRichard Lowerefer to the name of the member. 1023bbf21555SRichard LoweThe name is encoded as an offset into the string table as described by the 1024bbf21555SRichard Lowesection 1025bbf21555SRichard Lowe.Sx String Identifiers . 1026bbf21555SRichard LoweThe members 1027bbf21555SRichard Lowe.Sy ctm_type 1028bbf21555SRichard Loweand 1029bbf21555SRichard Lowe.Sy ctlm_type 1030bbf21555SRichard Loweboth refer to the type of the member. 1031bbf21555SRichard LoweThey are encoded as per the section 1032bbf21555SRichard Lowe.Sx Type Identifiers . 1033bbf21555SRichard Lowe.Lp 1034bbf21555SRichard LoweThe last piece of information that is present is the offset which describes the 1035bbf21555SRichard Loweoffset in memory that the member begins at. 1036bbf21555SRichard LoweFor unions, this value will always be zero because the start of unions in memory 1037bbf21555SRichard Loweis always zero. 1038bbf21555SRichard LoweFor structures, this is the offset in 1039bbf21555SRichard Lowe.Sy bits 1040bbf21555SRichard Lowethat the member begins at. 1041bbf21555SRichard LoweNote that a compiler may lay out a type with padding. 1042bbf21555SRichard LoweThis means that the difference in offset between two consecutive members may be 1043bbf21555SRichard Lowelarger than the size of the member. 1044bbf21555SRichard LoweWhen the size of the overall structure is strictly less than 8192 bytes, the 1045bbf21555SRichard Lowenormal structure, 1046bbf21555SRichard Lowe.Sy ctf_member_t , 1047bbf21555SRichard Loweis used and the offset in bits is stored in the member 1048bbf21555SRichard Lowe.Em ctm_offset . 1049bbf21555SRichard LoweHowever, when the size of the structure is greater than or equal to 8192 bytes, 1050bbf21555SRichard Lowethen the number of bits is split into two 32-bit quantities. 1051bbf21555SRichard LoweOne member, 1052bbf21555SRichard Lowe.Em ctlm_offsethi , 1053bbf21555SRichard Lowerepresents the upper 32 bits of the offset, while the other member, 1054bbf21555SRichard Lowe.Em ctlm_offsetlo , 1055bbf21555SRichard Lowerepresents the lower 32 bits of the offset. 1056bbf21555SRichard LoweThese can be joined together to get a 64-bit sized offset in bits by shifting 1057bbf21555SRichard Lowethe member 1058bbf21555SRichard Lowe.Em ctlm_offsethi 1059bbf21555SRichard Loweto the left by thirty two and then doing a binary or of 1060bbf21555SRichard Lowe.Em ctlm_offsetlo . 1061bbf21555SRichard Lowe.Ss Encoding of Enumerations 1062bbf21555SRichard LoweEnumerations, noted by the type 1063bbf21555SRichard Lowe.Sy CTF_K_ENUM , 1064bbf21555SRichard Loweare similar to structures. 1065bbf21555SRichard LoweEnumerations use the variable list to note the number of values that the 1066bbf21555SRichard Loweenumeration contains, which we'll term enumerators. 1067bbf21555SRichard LoweIn C, an enumeration is always equivalent to the intrinsic type 1068bbf21555SRichard Lowe.Sy int , 1069bbf21555SRichard Lowethus the value of the member 1070bbf21555SRichard Lowe.Em ctt_size 1071bbf21555SRichard Loweis always the size of an integer which is determined based on the current model. 1072bbf21555SRichard LoweFor illumos systems, this will always be 4, as an integer is always defined to 1073bbf21555SRichard Lowebe 4 bytes large in both 1074bbf21555SRichard Lowe.Sy ILP32 1075bbf21555SRichard Loweand 1076bbf21555SRichard Lowe.Sy LP64 , 1077bbf21555SRichard Loweregardless of the architecture. 1078bbf21555SRichard Lowe.Lp 1079bbf21555SRichard LoweThe enumerators encoded in an enumeration have the following structure in the 1080bbf21555SRichard Lowevariable list: 1081bbf21555SRichard Lowe.Bd -literal 1082bbf21555SRichard Lowetypedef struct ctf_enum { 1083bbf21555SRichard Lowe uint_t cte_name; /* reference to name in string table */ 1084bbf21555SRichard Lowe int cte_value; /* value associated with this name */ 1085bbf21555SRichard Lowe} ctf_enum_t; 1086bbf21555SRichard Lowe.Ed 1087bbf21555SRichard Lowe.Pp 1088bbf21555SRichard LoweThe member 1089bbf21555SRichard Lowe.Em cte_name 1090bbf21555SRichard Lowerefers to the name of the enumerator's value, it is encoded according to the 1091bbf21555SRichard Lowerules in the section 1092bbf21555SRichard Lowe.Sx String Identifiers . 1093bbf21555SRichard LoweThe member 1094bbf21555SRichard Lowe.Em cte_value 1095bbf21555SRichard Lowecontains the integer value of this enumerator. 1096bbf21555SRichard Lowe.Ss Encoding of Forward References 1097bbf21555SRichard LoweForward references, types of kind 1098bbf21555SRichard Lowe.Sy CTF_K_FORWARD , 1099bbf21555SRichard Lowein a 1100bbf21555SRichard Lowe.Nm 1101bbf21555SRichard Lowefile refer to types which may not have a definition at all, only a name. 1102bbf21555SRichard LoweIf the 1103bbf21555SRichard Lowe.Nm 1104bbf21555SRichard Lowefile is a child, then it may be that the forward is resolved to an 1105bbf21555SRichard Loweactual type in the parent, otherwise the definition may be in another 1106bbf21555SRichard Lowe.Nm 1107bbf21555SRichard Lowecontainer or may not be known at all. 1108bbf21555SRichard LoweThe only member of the 1109bbf21555SRichard Lowe.Sy ctf_type_t 1110bbf21555SRichard Lowethat matters for a forward declaration is the 1111bbf21555SRichard Lowe.Em ctt_name 1112bbf21555SRichard Lowewhich points to the name of the forward reference in the string table as 1113bbf21555SRichard Lowedescribed earlier. 1114bbf21555SRichard LoweThere is no other information recorded for forward references. 1115bbf21555SRichard Lowe.Ss Encoding of Pointers, Typedefs, Volatile, Const, and Restrict 1116bbf21555SRichard LowePointers, typedefs, volatile, const, and restrict are all similar in 1117bbf21555SRichard Lowe.Nm . 1118bbf21555SRichard LoweThey all refer to another type. 1119bbf21555SRichard LoweIn the case of typedefs, they provide an alternate name, while volatile, const, 1120bbf21555SRichard Loweand restrict change how the type is interpreted in the C programming language. 1121bbf21555SRichard LoweThis covers the 1122bbf21555SRichard Lowe.Nm 1123bbf21555SRichard Lowekinds 1124bbf21555SRichard Lowe.Sy CTF_K_POINTER , 1125bbf21555SRichard Lowe.Sy CTF_K_TYPEDEF , 1126bbf21555SRichard Lowe.Sy CTF_K_VOLATILE , 1127bbf21555SRichard Lowe.Sy CTF_K_RESTRICT , 1128bbf21555SRichard Loweand 1129bbf21555SRichard Lowe.Sy CTF_K_CONST . 1130bbf21555SRichard Lowe.Lp 1131bbf21555SRichard LoweThese types have no variable list entries and use the member 1132bbf21555SRichard Lowe.Em ctt_type 1133bbf21555SRichard Loweto refer to the base type that they modify. 1134bbf21555SRichard Lowe.Ss Encoding of Unknown Types 1135bbf21555SRichard LoweTypes with the kind 1136bbf21555SRichard Lowe.Sy CTF_K_UNKNOWN 1137bbf21555SRichard Loweare used to indicate gaps in the type identifier space. 1138bbf21555SRichard LoweThese entries consume an identifier, but do not define anything. 1139bbf21555SRichard LoweNothing should refer to these gap identifiers. 1140bbf21555SRichard Lowe.Ss Dependencies Between Types 1141bbf21555SRichard LoweC types can be imagined as a directed, cyclic, graph. 1142bbf21555SRichard LoweStructures and unions may refer to each other in a way that creates a cyclic 1143bbf21555SRichard Lowedependency. 1144bbf21555SRichard LoweIn cases such as these, the entire type section must be read in and processed. 1145bbf21555SRichard LoweConsumers must not assume that every type can be laid out in dependency order; 1146bbf21555SRichard Lowethey cannot. 1147bbf21555SRichard Lowe.Ss The String Section 1148bbf21555SRichard LoweThe last section of the 1149bbf21555SRichard Lowe.Nm 1150bbf21555SRichard Lowefile is the 1151bbf21555SRichard Lowe.Sy string 1152bbf21555SRichard Lowesection. 1153bbf21555SRichard LoweThis section encodes all of the strings that appear throughout the other 1154bbf21555SRichard Lowesections. 1155bbf21555SRichard LoweIt is laid out as a series of characters followed by a null terminator. 1156bbf21555SRichard LoweGenerally, all names are written out in ASCII, as most C compilers do not allow 1157bbf21555SRichard Loweand characters to appear in identifiers outside of a subset of ASCII. 1158bbf21555SRichard LoweHowever, any extended characters sets should be written out as a series of UTF-8 1159bbf21555SRichard Lowebytes. 1160bbf21555SRichard Lowe.Lp 1161bbf21555SRichard LoweThe first entry in the section, at offset zero, is a single null 1162bbf21555SRichard Loweterminator to reference the empty string. 1163bbf21555SRichard LoweFollowing that, each C string should be written out, including the null 1164bbf21555SRichard Loweterminator. 1165bbf21555SRichard LoweOffsets that refer to something in this section should refer to the first byte 1166bbf21555SRichard Lowewhich begins a string. 1167bbf21555SRichard LoweBeyond the first byte in the section being the null terminator, the order of 1168bbf21555SRichard Lowestrings is unimportant. 1169bbf21555SRichard Lowe.Sh Data Encoding and ELF Considerations 1170bbf21555SRichard Lowe.Nm 1171bbf21555SRichard Lowedata is generally included in ELF objects which specify information to 1172bbf21555SRichard Loweidentify the architecture and endianness of the file. 1173bbf21555SRichard LoweA 1174bbf21555SRichard Lowe.Nm 1175bbf21555SRichard Lowecontainer inside such an object must match the endianness of the ELF object. 1176bbf21555SRichard LoweAside from the question of the endian encoding of data, there should be no other 1177bbf21555SRichard Lowedifferences between architectures. 1178bbf21555SRichard LoweWhile many of the types in this document refer to non-fixed size C integral 1179bbf21555SRichard Lowetypes, they are equivalent in the models 1180bbf21555SRichard Lowe.Sy ILP32 1181bbf21555SRichard Loweand 1182bbf21555SRichard Lowe.Sy LP64 . 1183bbf21555SRichard LoweIf any other model is being used with 1184bbf21555SRichard Lowe.Nm 1185bbf21555SRichard Lowedata that has different sizes, then it must not use the model's sizes for 1186bbf21555SRichard Lowethose integral types and instead use the fixed size equivalents based on an 1187bbf21555SRichard Lowe.Sy ILP32 1188bbf21555SRichard Loweenvironment. 1189bbf21555SRichard Lowe.Lp 1190bbf21555SRichard LoweWhen placing a 1191bbf21555SRichard Lowe.Nm 1192bbf21555SRichard Lowecontainer inside of an ELF object, there are certain conventions that are 1193bbf21555SRichard Loweexpected for the purposes of tooling being able to find the 1194bbf21555SRichard Lowe.Nm 1195bbf21555SRichard Lowedata. 1196bbf21555SRichard LoweIn particular, a given ELF object should only contain a single 1197bbf21555SRichard Lowe.Nm 1198bbf21555SRichard Lowesection. 1199bbf21555SRichard LoweMultiple containers should be merged together into a single one. 1200bbf21555SRichard Lowe.Lp 1201bbf21555SRichard LoweThe 1202bbf21555SRichard Lowe.Nm 1203bbf21555SRichard Lowefile should be included in its own ELF section. 1204bbf21555SRichard LoweThe section's name must be 1205bbf21555SRichard Lowe.Ql .SUNW_ctf . 1206bbf21555SRichard LoweThe type of the section must be 1207bbf21555SRichard Lowe.Sy SHT_PROGBITS . 1208bbf21555SRichard LoweThe section should have a link set to the symbol table and its address 1209bbf21555SRichard Lowealignment must be 4. 1210bbf21555SRichard Lowe.Sh SEE ALSO 1211bbf21555SRichard Lowe.Xr mdb 1 , 1212bbf21555SRichard Lowe.Xr gelf 3ELF , 1213bbf21555SRichard Lowe.Xr libelf 3LIB , 1214bbf21555SRichard Lowe.Xr a.out 5 , 1215bbf21555SRichard Lowe.Xr dtrace 8 1216