xref: /freebsd/cddl/contrib/opensolaris/lib/libctf/common/ctf.5 (revision ef36b3f75658d201edb495068db5e1be49593de5)
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.\"
1438d120bcSMark Johnston.Dd Sep 26, 2014
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
42*ef36b3f7SMark Johnstonobject.
43*ef36b3f7SMark 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
5538d120bcSMark JohnstonOn illumos systems,
5638d120bcSMark Johnston.Nm
57*ef36b3f7SMark Johnstondata is consumed by multiple programs.
58*ef36b3f7SMark JohnstonIt can be used by the modular debugger,
5938d120bcSMark Johnston.Xr mdb 1 ,
6038d120bcSMark Johnstonas well as by
61*ef36b3f7SMark Johnston.Xr dtrace 1 .
6238d120bcSMark JohnstonProgrammatic access to
6338d120bcSMark Johnston.Nm
6438d120bcSMark Johnstondata can be obtained through
6538d120bcSMark Johnston.Xr libctf 3LIB .
6638d120bcSMark Johnston.Lp
6738d120bcSMark JohnstonThe
6838d120bcSMark Johnston.Nm
69*ef36b3f7SMark Johnstonfile format is broken down into seven different sections.
70*ef36b3f7SMark JohnstonThe first section is the
7138d120bcSMark Johnston.Sy preamble
7238d120bcSMark Johnstonand
7338d120bcSMark Johnston.Sy header ,
7438d120bcSMark Johnstonwhich describes the version of the
7538d120bcSMark Johnston.Nm
7638d120bcSMark Johnstonfile, links it has to other
7738d120bcSMark Johnston.Nm
78*ef36b3f7SMark Johnstonfiles, and the sizes of the other sections.
79*ef36b3f7SMark JohnstonThe next section is the
8038d120bcSMark Johnston.Sy label
8138d120bcSMark Johnstonsection,
8238d120bcSMark Johnstonwhich provides a way of identifying similar groups of
8338d120bcSMark Johnston.Nm
84*ef36b3f7SMark Johnstondata across multiple files.
85*ef36b3f7SMark JohnstonThis is followed by the
8638d120bcSMark Johnston.Sy object
8738d120bcSMark Johnstoninformation section, which describes the type of global
88*ef36b3f7SMark Johnstonsymbols.
89*ef36b3f7SMark JohnstonThe subsequent section is the
9038d120bcSMark Johnston.Sy function
9138d120bcSMark Johnstoninformation section, which describes the return
92*ef36b3f7SMark Johnstontypes and arguments of functions.
93*ef36b3f7SMark JohnstonThe next section is the
9438d120bcSMark Johnston.Sy type
9538d120bcSMark Johnstoninformation section, which describes
9638d120bcSMark Johnstonthe format and layout of the C types themselves, and finally the last
9738d120bcSMark Johnstonsection is the
9838d120bcSMark Johnston.Sy string
9938d120bcSMark Johnstonsection, which contains the names of types, enumerations, members, and
10038d120bcSMark Johnstonlabels.
10138d120bcSMark Johnston.Lp
10238d120bcSMark JohnstonWhile strictly speaking, only the
10338d120bcSMark Johnston.Sy preamble
10438d120bcSMark Johnstonand
10538d120bcSMark Johnston.Sy header
10638d120bcSMark Johnstonare required, to be actually useful, both the type and string
10738d120bcSMark Johnstonsections are necessary.
10838d120bcSMark Johnston.Lp
10938d120bcSMark JohnstonA
11038d120bcSMark Johnston.Nm
11138d120bcSMark Johnstonfile may contain all of the type information that it requires, or it
11238d120bcSMark Johnstonmay optionally refer to another
11338d120bcSMark Johnston.Nm
114*ef36b3f7SMark Johnstonfile which holds the remaining types.
115*ef36b3f7SMark JohnstonWhen a
11638d120bcSMark Johnston.Nm
11738d120bcSMark Johnstonfile refers to another file, it is called the
11838d120bcSMark Johnston.Sy child
11938d120bcSMark Johnstonand the file it refers to is called the
12038d120bcSMark Johnston.Sy parent .
121*ef36b3f7SMark JohnstonA given file may only refer to one parent.
122*ef36b3f7SMark JohnstonThis process is called
12338d120bcSMark Johnston.Em uniquification
12438d120bcSMark Johnstonbecause it ensures each child only has type information that is
125*ef36b3f7SMark Johnstonunique to it.
126*ef36b3f7SMark JohnstonA common example of this is that most kernel modules in illumos are uniquified
127*ef36b3f7SMark Johnstonagainst the kernel module
12838d120bcSMark Johnston.Sy genunix
12938d120bcSMark Johnstonand the type information that comes from the
13038d120bcSMark Johnston.Sy IP
131*ef36b3f7SMark Johnstonmodule.
132*ef36b3f7SMark JohnstonThis means that a module only has types that are unique to itself and the most
133*ef36b3f7SMark Johnstoncommon types in the kernel are not duplicated.
13438d120bcSMark Johnston.Sh FILE FORMAT
13538d120bcSMark JohnstonThis documents version
13638d120bcSMark Johnston.Em two
13738d120bcSMark Johnstonof the
13838d120bcSMark Johnston.Nm
139*ef36b3f7SMark Johnstonfile format.
140*ef36b3f7SMark JohnstonAll applications and tools currently produce and operate on this version.
14138d120bcSMark Johnston.Lp
14238d120bcSMark JohnstonThe file format can be summarized with the following image, the
14338d120bcSMark Johnstonfollowing sections will cover this in more detail.
14438d120bcSMark Johnston.Bd -literal
14538d120bcSMark Johnston
14638d120bcSMark Johnston         +-------------+  0t0
14738d120bcSMark Johnston+--------| Preamble    |
14838d120bcSMark Johnston|        +-------------+  0t4
14938d120bcSMark Johnston|+-------| Header      |
15038d120bcSMark Johnston||       +-------------+  0t36 + cth_lbloff
15138d120bcSMark Johnston||+------| Labels      |
15238d120bcSMark Johnston|||      +-------------+  0t36 + cth_objtoff
15338d120bcSMark Johnston|||+-----| Objects     |
15438d120bcSMark Johnston||||     +-------------+  0t36 + cth_funcoff
15538d120bcSMark Johnston||||+----| Functions   |
15638d120bcSMark Johnston|||||    +-------------+  0t36 + cth_typeoff
15738d120bcSMark Johnston|||||+---| Types       |
15838d120bcSMark Johnston||||||   +-------------+  0t36 + cth_stroff
15938d120bcSMark Johnston||||||+--| Strings     |
16038d120bcSMark Johnston|||||||  +-------------+  0t36 + cth_stroff + cth_strlen
16138d120bcSMark Johnston|||||||
16238d120bcSMark Johnston|||||||
16338d120bcSMark Johnston|||||||
16438d120bcSMark Johnston|||||||    +-- magic -   vers   flags
16538d120bcSMark Johnston|||||||    |          |    |      |
16638d120bcSMark Johnston|||||||   +------+------+------+------+
16738d120bcSMark Johnston+---------| 0xcf | 0xf1 | 0x02 | 0x00 |
16838d120bcSMark Johnston ||||||   +------+------+------+------+
16938d120bcSMark Johnston ||||||   0      1      2      3      4
17038d120bcSMark Johnston ||||||
17138d120bcSMark Johnston ||||||    + parent label        + objects
17238d120bcSMark Johnston ||||||    |       + parent name |     + functions    + strings
17338d120bcSMark Johnston ||||||    |       |     + label |     |      + types |       + strlen
17438d120bcSMark Johnston ||||||    |       |     |       |     |      |       |       |
17538d120bcSMark Johnston ||||||   +------+------+------+------+------+-------+-------+-------+
17638d120bcSMark Johnston +--------| 0x00 | 0x00 | 0x00 | 0x08 | 0x36 | 0x110 | 0x5f4 | 0x611 |
17738d120bcSMark Johnston  |||||   +------+------+------+------+------+-------+-------+-------+
17838d120bcSMark Johnston  |||||   0x04   0x08   0x0c   0x10   0x14    0x18    0x1c    0x20   0x24
17938d120bcSMark Johnston  |||||
18038d120bcSMark Johnston  |||||         + Label name
18138d120bcSMark Johnston  |||||         |       + Label type
18238d120bcSMark Johnston  |||||         |       |       + Next label
18338d120bcSMark Johnston  |||||         |       |       |
18438d120bcSMark Johnston  |||||       +-------+------+-----+
18538d120bcSMark Johnston  +-----------| 0x01  | 0x42 | ... |
18638d120bcSMark Johnston   ||||       +-------+------+-----+
18738d120bcSMark Johnston   ||||  cth_lbloff   +0x4   +0x8  cth_objtoff
18838d120bcSMark Johnston   ||||
18938d120bcSMark Johnston   ||||
19038d120bcSMark Johnston   |||| Symidx  0t15   0t43   0t44
19138d120bcSMark Johnston   ||||       +------+------+------+-----+
19238d120bcSMark Johnston   +----------| 0x00 | 0x42 | 0x36 | ... |
19338d120bcSMark Johnston    |||       +------+------+------+-----+
19438d120bcSMark Johnston    ||| cth_objtoff  +0x2   +0x4   +0x6   cth_funcoff
19538d120bcSMark Johnston    |||
19638d120bcSMark Johnston    |||        + CTF_TYPE_INFO         + CTF_TYPE_INFO
19738d120bcSMark Johnston    |||        |        + Return type  |
19838d120bcSMark Johnston    |||        |        |       + arg0 |
19938d120bcSMark Johnston    |||       +--------+------+------+-----+
20038d120bcSMark Johnston    +---------| 0x2c10 | 0x08 | 0x0c | ... |
20138d120bcSMark Johnston     ||       +--------+------+------+-----+
20238d120bcSMark Johnston     || cth_funcff     +0x2   +0x4   +0x6  cth_typeoff
20338d120bcSMark Johnston     ||
20438d120bcSMark Johnston     ||         + ctf_stype_t for type 1
20538d120bcSMark Johnston     ||         |  integer           + integer encoding
20638d120bcSMark Johnston     ||         |                    |          + ctf_stype_t for type 2
20738d120bcSMark Johnston     ||         |                    |          |
20838d120bcSMark Johnston     ||       +--------------------+-----------+-----+
20938d120bcSMark Johnston     +--------| 0x19 * 0xc01 * 0x0 | 0x1000000 | ... |
21038d120bcSMark Johnston      |       +--------------------+-----------+-----+
21138d120bcSMark Johnston      | cth_typeoff               +0x08      +0x0c  cth_stroff
21238d120bcSMark Johnston      |
21338d120bcSMark Johnston      |     +--- str 0
21438d120bcSMark Johnston      |     |    +--- str 1       + str 2
21538d120bcSMark Johnston      |     |    |                |
21638d120bcSMark Johnston      |     v    v                v
21738d120bcSMark Johnston      |   +----+---+---+---+----+---+---+---+---+---+----+
21838d120bcSMark Johnston      +---| \\0 | i | n | t | \\0 | f | o | o | _ | t | \\0 |
21938d120bcSMark Johnston          +----+---+---+---+----+---+---+---+---+---+----+
22038d120bcSMark Johnston          0    1   2   3   4    5   6   7   8   9   10   11
22138d120bcSMark Johnston.Ed
22238d120bcSMark Johnston.Lp
22338d120bcSMark JohnstonEvery
22438d120bcSMark Johnston.Nm
22538d120bcSMark Johnstonfile begins with a
22638d120bcSMark Johnston.Sy preamble ,
22738d120bcSMark Johnstonfollowed by a
22838d120bcSMark Johnston.Sy header .
22938d120bcSMark JohnstonThe
23038d120bcSMark Johnston.Sy preamble
23138d120bcSMark Johnstonis defined as follows:
23238d120bcSMark Johnston.Bd -literal
23338d120bcSMark Johnstontypedef struct ctf_preamble {
23438d120bcSMark Johnston	ushort_t ctp_magic;	/* magic number (CTF_MAGIC) */
23538d120bcSMark Johnston	uchar_t ctp_version;	/* data format version number (CTF_VERSION) */
23638d120bcSMark Johnston	uchar_t ctp_flags;	/* flags (see below) */
23738d120bcSMark Johnston} ctf_preamble_t;
23838d120bcSMark Johnston.Ed
23938d120bcSMark Johnston.Pp
24038d120bcSMark JohnstonThe
24138d120bcSMark Johnston.Sy preamble
24238d120bcSMark Johnstonis four bytes long and must be four byte aligned.
24338d120bcSMark JohnstonThis
24438d120bcSMark Johnston.Sy preamble
24538d120bcSMark Johnstondefines the version of the
24638d120bcSMark Johnston.Nm
247*ef36b3f7SMark Johnstonfile which defines the format of the rest of the header.
248*ef36b3f7SMark JohnstonWhile the header may change in subsequent versions, the preamble will not change
24938d120bcSMark Johnstonacross versions, though the interpretation of its flags may change from
250*ef36b3f7SMark Johnstonversion to version.
251*ef36b3f7SMark JohnstonThe
25238d120bcSMark Johnston.Em ctp_magic
25338d120bcSMark Johnstonmember defines the magic number for the
25438d120bcSMark Johnston.Nm
255*ef36b3f7SMark Johnstonfile format.
256*ef36b3f7SMark JohnstonThis must always be
25738d120bcSMark Johnston.Li 0xcff1 .
25838d120bcSMark JohnstonIf another value is encountered, then the file should not be treated as
25938d120bcSMark Johnstona
26038d120bcSMark Johnston.Nm
261*ef36b3f7SMark Johnstonfile.
262*ef36b3f7SMark JohnstonThe
26338d120bcSMark Johnston.Em ctp_version
26438d120bcSMark Johnstonmember defines the version of the
26538d120bcSMark Johnston.Nm
266*ef36b3f7SMark Johnstonfile.
267*ef36b3f7SMark JohnstonThe current version is
26838d120bcSMark Johnston.Li 2 .
269*ef36b3f7SMark JohnstonIt is possible to encounter an unsupported version.
270*ef36b3f7SMark JohnstonIn that case, software should not try to parse the format, as it may have
271*ef36b3f7SMark Johnstonchanged.
27238d120bcSMark JohnstonFinally, the
27338d120bcSMark Johnston.Em ctp_flags
27438d120bcSMark Johnstonmember describes aspects of the file which modify its interpretation.
27538d120bcSMark JohnstonThe following flags are currently defined:
27638d120bcSMark Johnston.Bd -literal
27738d120bcSMark Johnston#define	CTF_F_COMPRESS		0x01
27838d120bcSMark Johnston.Ed
27938d120bcSMark Johnston.Pp
28038d120bcSMark JohnstonThe flag
28138d120bcSMark Johnston.Sy CTF_F_COMPRESS
28238d120bcSMark Johnstonindicates that the body of the
28338d120bcSMark Johnston.Nm
28438d120bcSMark Johnstonfile, all the data following the
28538d120bcSMark Johnston.Sy header ,
28638d120bcSMark Johnstonhas been compressed through the
28738d120bcSMark Johnston.Sy zlib
28838d120bcSMark Johnstonlibrary and its
28938d120bcSMark Johnston.Sy deflate
290*ef36b3f7SMark Johnstonalgorithm.
291*ef36b3f7SMark JohnstonIf this flag is not present, then the body has not been compressed and no
292*ef36b3f7SMark Johnstonspecial action is needed to interpret it.
293*ef36b3f7SMark JohnstonAll offsets into the data as described by
29438d120bcSMark Johnston.Sy header ,
29538d120bcSMark Johnstonalways refer to the
29638d120bcSMark Johnston.Sy uncompressed
29738d120bcSMark Johnstondata.
29838d120bcSMark Johnston.Lp
29938d120bcSMark JohnstonIn version two of the
30038d120bcSMark Johnston.Nm
30138d120bcSMark Johnstonfile format, the
30238d120bcSMark Johnston.Sy header
30338d120bcSMark Johnstondenotes whether whether or not this
30438d120bcSMark Johnston.Nm
30538d120bcSMark Johnstonfile is the child of another
30638d120bcSMark Johnston.Nm
307*ef36b3f7SMark Johnstonfile and also indicates the size of the remaining sections.
308*ef36b3f7SMark JohnstonThe structure for the
30938d120bcSMark Johnston.Sy header ,
31038d120bcSMark Johnstonlogically contains a copy of the
31138d120bcSMark Johnston.Sy preamble
31238d120bcSMark Johnstonand the two have a combined size of 36 bytes.
31338d120bcSMark Johnston.Bd -literal
31438d120bcSMark Johnstontypedef struct ctf_header {
31538d120bcSMark Johnston	ctf_preamble_t cth_preamble;
31638d120bcSMark Johnston	uint_t cth_parlabel;	/* ref to name of parent lbl uniq'd against */
31738d120bcSMark Johnston	uint_t cth_parname;	/* ref to basename of parent */
31838d120bcSMark Johnston	uint_t cth_lbloff;	/* offset of label section */
31938d120bcSMark Johnston	uint_t cth_objtoff;	/* offset of object section */
32038d120bcSMark Johnston	uint_t cth_funcoff;	/* offset of function section */
32138d120bcSMark Johnston	uint_t cth_typeoff;	/* offset of type section */
32238d120bcSMark Johnston	uint_t cth_stroff;	/* offset of string section */
32338d120bcSMark Johnston	uint_t cth_strlen;	/* length of string section in bytes */
32438d120bcSMark Johnston} ctf_header_t;
32538d120bcSMark Johnston.Ed
32638d120bcSMark Johnston.Pp
32738d120bcSMark JohnstonAfter the
32838d120bcSMark Johnston.Sy preamble ,
32938d120bcSMark Johnstonthe next two members
33038d120bcSMark Johnston.Em cth_parlablel
33138d120bcSMark Johnstonand
33238d120bcSMark Johnston.Em cth_parname ,
333*ef36b3f7SMark Johnstonare used to identify the parent.
334*ef36b3f7SMark JohnstonThe value of both members are offsets into the
33538d120bcSMark Johnston.Sy string
336*ef36b3f7SMark Johnstonsection which point to the start of a null-terminated string.
337*ef36b3f7SMark JohnstonFor more information on the encoding of strings, see the subsection on
33838d120bcSMark Johnston.Sx String Identifiers .
33938d120bcSMark JohnstonIf the value of either is zero, then there is no entry for that
340*ef36b3f7SMark Johnstonmember.
341*ef36b3f7SMark JohnstonIf the member
34238d120bcSMark Johnston.Em cth_parlabel
34338d120bcSMark Johnstonis set, then the
34438d120bcSMark Johnston.Em ctf_parname
34538d120bcSMark Johnstonmember must be set, otherwise it will not be possible to find the
346*ef36b3f7SMark Johnstonparent.
347*ef36b3f7SMark JohnstonIf
34838d120bcSMark Johnston.Em ctf_parname
34938d120bcSMark Johnstonis set, it is not necessary to define
35038d120bcSMark Johnston.Em cth_parlabel ,
351*ef36b3f7SMark Johnstonas the parent may not have a label.
352*ef36b3f7SMark JohnstonFor more information on labels and their interpretation, see
35338d120bcSMark Johnston.Sx The Label Section .
35438d120bcSMark Johnston.Lp
35538d120bcSMark JohnstonThe remaining members (excepting
35638d120bcSMark Johnston.Em cth_strlen )
357*ef36b3f7SMark Johnstondescribe the beginning of the corresponding sections.
358*ef36b3f7SMark JohnstonThese offsets are relative to the end of the
35938d120bcSMark Johnston.Sy header .
36038d120bcSMark JohnstonTherefore, something with an offset of 0 is at an offset of thirty-six
36138d120bcSMark Johnstonbytes relative to the start of the
36238d120bcSMark Johnston.Nm
363*ef36b3f7SMark Johnstonfile.
364*ef36b3f7SMark JohnstonThe difference between members indicates the size of the section itself.
365*ef36b3f7SMark JohnstonDifferent offsets have different alignment requirements.
366*ef36b3f7SMark JohnstonThe start of the
36738d120bcSMark Johnston.Em cth_objotoff
36838d120bcSMark Johnstonand
36938d120bcSMark Johnston.Em cth_funcoff
37038d120bcSMark Johnstonmust be two byte aligned, while the sections
37138d120bcSMark Johnston.Em cth_lbloff
37238d120bcSMark Johnstonand
37338d120bcSMark Johnston.Em cth_typeoff
374*ef36b3f7SMark Johnstonmust be four-byte aligned.
375*ef36b3f7SMark JohnstonThe section
37638d120bcSMark Johnston.Em cth_stroff
377*ef36b3f7SMark Johnstonhas no alignment requirements.
378*ef36b3f7SMark JohnstonTo calculate the size of a given section, excepting the
37938d120bcSMark Johnston.Sy string
380*ef36b3f7SMark Johnstonsection, one should subtract the offset of the section from the following one.
381*ef36b3f7SMark JohnstonFor example, the size of the
38238d120bcSMark Johnston.Sy types
38338d120bcSMark Johnstonsection can be calculated by subtracting
38438d120bcSMark Johnston.Em cth_stroff
38538d120bcSMark Johnstonfrom
38638d120bcSMark Johnston.Em cth_typeoff .
38738d120bcSMark Johnston.Lp
38838d120bcSMark JohnstonFinally, the member
38938d120bcSMark Johnston.Em cth_strlen
390*ef36b3f7SMark Johnstondescribes the length of the string section itself.
391*ef36b3f7SMark JohnstonFrom it, you can also calculate the size of the entire
39238d120bcSMark Johnston.Nm
39338d120bcSMark Johnstonfile by adding together the size of the
39438d120bcSMark Johnston.Sy ctf_header_t ,
39538d120bcSMark Johnstonthe offset of the string section in
39638d120bcSMark Johnston.Em cth_stroff ,
39738d120bcSMark Johnstonand the size of the string section in
39838d120bcSMark Johnston.Em cth_srlen .
39938d120bcSMark Johnston.Ss Type Identifiers
40038d120bcSMark JohnstonThrough the
40138d120bcSMark Johnston.Nm ctf
402*ef36b3f7SMark Johnstondata, types are referred to by identifiers.
403*ef36b3f7SMark JohnstonA given
40438d120bcSMark Johnston.Nm
405*ef36b3f7SMark Johnstonfile supports up to 32767 (0x7fff) types.
406*ef36b3f7SMark JohnstonThe first valid type identifier is 0x1.
40738d120bcSMark JohnstonWhen a given
40838d120bcSMark Johnston.Nm
40938d120bcSMark Johnstonfile is a child, indicated by a non-zero entry for the
41038d120bcSMark Johnston.Sy header Ns 's
41138d120bcSMark Johnston.Em cth_parname ,
41238d120bcSMark Johnstonthen the first valid type identifier is 0x8000 and the last is 0xffff.
41338d120bcSMark JohnstonIn this case, type identifiers 0x1 through 0x7fff are references to the
41438d120bcSMark Johnstonparent.
41538d120bcSMark Johnston.Lp
41638d120bcSMark JohnstonThe type identifier zero is a sentinel value used to indicate that there
41738d120bcSMark Johnstonis no type information available or it is an unknown type.
41838d120bcSMark Johnston.Lp
41938d120bcSMark JohnstonThroughout the file format, the identifier is stored in different sized
42038d120bcSMark Johnstonvalues; however, the minimum size to represent a given identifier is a
42138d120bcSMark Johnston.Sy uint16_t .
42238d120bcSMark JohnstonOther consumers of
42338d120bcSMark Johnston.Nm
42438d120bcSMark Johnstoninformation may use larger or opaque identifiers.
42538d120bcSMark Johnston.Ss String Identifiers
42638d120bcSMark JohnstonString identifiers are always encoded as four byte unsigned integers
427*ef36b3f7SMark Johnstonwhich are an offset into a string table.
428*ef36b3f7SMark JohnstonThe
42938d120bcSMark Johnston.Nm
43038d120bcSMark Johnstonformat supports two different string tables which have an identifier of
431*ef36b3f7SMark Johnstonzero or one.
432*ef36b3f7SMark JohnstonThis identifier is stored in the high-order bit of the unsigned four byte
433*ef36b3f7SMark Johnstonoffset.
434*ef36b3f7SMark JohnstonTherefore, the maximum supported offset into one of these tables is 0x7ffffffff.
43538d120bcSMark Johnston.Lp
43638d120bcSMark JohnstonTable identifier zero, always refers to the
43738d120bcSMark Johnston.Sy string
438*ef36b3f7SMark Johnstonsection in the CTF file itself.
439*ef36b3f7SMark JohnstonString table identifier one refers to an external string table which is the ELF
440*ef36b3f7SMark Johnstonstring table for the ELF symbol table associated with the
44138d120bcSMark Johnston.Nm
44238d120bcSMark Johnstoncontainer.
44338d120bcSMark Johnston.Ss Type Encoding
44438d120bcSMark JohnstonEvery
44538d120bcSMark Johnston.Nm
44638d120bcSMark Johnstontype begins with metadata encoded into a
44738d120bcSMark Johnston.Sy uint16_t .
44838d120bcSMark JohnstonThis encoded information tells us three different pieces of information:
44938d120bcSMark Johnston.Bl -bullet -offset indent -compact
45038d120bcSMark Johnston.It
45138d120bcSMark JohnstonThe kind of the type
45238d120bcSMark Johnston.It
45338d120bcSMark JohnstonWhether this type is a root type or not
45438d120bcSMark Johnston.It
45538d120bcSMark JohnstonThe length of the variable data
45638d120bcSMark Johnston.El
45738d120bcSMark Johnston.Lp
45838d120bcSMark JohnstonThe 16 bits that make up the encoding are broken down such that you have
45938d120bcSMark Johnstonfive bits for the kind, one bit for indicating whether or not it is a
460*ef36b3f7SMark Johnstonroot type, and 10 bits for the variable length.
461*ef36b3f7SMark JohnstonThis is laid out as follows:
46238d120bcSMark Johnston.Bd -literal -offset indent
46338d120bcSMark Johnston+--------------------+
46438d120bcSMark Johnston| kind | root | vlen |
46538d120bcSMark Johnston+--------------------+
46638d120bcSMark Johnston15   11   10   9    0
46738d120bcSMark Johnston.Ed
46838d120bcSMark Johnston.Lp
469*ef36b3f7SMark JohnstonThe current version of the file format defines 14 different kinds.
470*ef36b3f7SMark JohnstonThe interpretation of these different kinds will be discussed in the section
47138d120bcSMark Johnston.Sx The Type Section .
47238d120bcSMark JohnstonIf a kind is encountered that is not listed below, then it is not a valid
47338d120bcSMark Johnston.Nm
474*ef36b3f7SMark Johnstonfile.
475*ef36b3f7SMark JohnstonThe kinds are defined as follows:
47638d120bcSMark Johnston.Bd -literal -offset indent
47738d120bcSMark Johnston#define	CTF_K_UNKNOWN	0
47838d120bcSMark Johnston#define	CTF_K_INTEGER	1
47938d120bcSMark Johnston#define	CTF_K_FLOAT	2
48038d120bcSMark Johnston#define	CTF_K_POINTER	3
48138d120bcSMark Johnston#define	CTF_K_ARRAY	4
48238d120bcSMark Johnston#define	CTF_K_FUNCTION	5
48338d120bcSMark Johnston#define	CTF_K_STRUCT	6
48438d120bcSMark Johnston#define	CTF_K_UNION	7
48538d120bcSMark Johnston#define	CTF_K_ENUM	8
48638d120bcSMark Johnston#define	CTF_K_FORWARD	9
48738d120bcSMark Johnston#define	CTF_K_TYPEDEF	10
48838d120bcSMark Johnston#define	CTF_K_VOLATILE	11
48938d120bcSMark Johnston#define	CTF_K_CONST	12
49038d120bcSMark Johnston#define	CTF_K_RESTRICT	13
49138d120bcSMark Johnston.Ed
49238d120bcSMark Johnston.Lp
49338d120bcSMark JohnstonPrograms directly reference many types; however, other types are referenced
494*ef36b3f7SMark Johnstonindirectly because they are part of some other structure.
495*ef36b3f7SMark JohnstonThese types that are referenced directly and used are called
49638d120bcSMark Johnston.Sy root
497*ef36b3f7SMark Johnstontypes.
498*ef36b3f7SMark JohnstonOther types may be used indirectly, for example, a program may reference
499*ef36b3f7SMark Johnstona structure directly, but not one of its members which has a type.
500*ef36b3f7SMark JohnstonThat type is not considered a
50138d120bcSMark Johnston.Sy root
502*ef36b3f7SMark Johnstontype.
503*ef36b3f7SMark JohnstonIf a type is a
50438d120bcSMark Johnston.Sy root
50538d120bcSMark Johnstontype, then it will have bit 10 set.
50638d120bcSMark Johnston.Lp
50738d120bcSMark JohnstonThe variable length section is specific to each kind and is discussed in the
50838d120bcSMark Johnstonsection
50938d120bcSMark Johnston.Sx The Type Section .
51038d120bcSMark Johnston.Lp
51138d120bcSMark JohnstonThe following macros are useful for constructing and deconstructing the encoded
51238d120bcSMark Johnstontype information:
51338d120bcSMark Johnston.Bd -literal -offset indent
51438d120bcSMark Johnston
51538d120bcSMark Johnston#define	CTF_MAX_VLEN	0x3ff
51638d120bcSMark Johnston#define	CTF_INFO_KIND(info)	(((info) & 0xf800) >> 11)
51738d120bcSMark Johnston#define	CTF_INFO_ISROOT(info)	(((info) & 0x0400) >> 10)
51838d120bcSMark Johnston#define	CTF_INFO_VLEN(info)	(((info) & CTF_MAX_VLEN))
51938d120bcSMark Johnston
52038d120bcSMark Johnston#define	CTF_TYPE_INFO(kind, isroot, vlen) \\
52138d120bcSMark Johnston	(((kind) << 11) | (((isroot) ? 1 : 0) << 10) | ((vlen) & CTF_MAX_VLEN))
52238d120bcSMark Johnston.Ed
52338d120bcSMark Johnston.Ss The Label Section
52438d120bcSMark JohnstonWhen consuming
52538d120bcSMark Johnston.Nm
52638d120bcSMark Johnstondata, it is often useful to know whether two different
52738d120bcSMark Johnston.Nm
528*ef36b3f7SMark Johnstoncontainers come from the same source base and version.
529*ef36b3f7SMark JohnstonFor example, when building illumos, there are many kernel modules that are built
530*ef36b3f7SMark Johnstonagainst a single collection of source code.
531*ef36b3f7SMark JohnstonA label is encoded into the
53238d120bcSMark Johnston.Nm
533*ef36b3f7SMark Johnstonfiles that corresponds with the particular build.
534*ef36b3f7SMark JohnstonThis ensures that if files on the system were to become mixed up from multiple
535*ef36b3f7SMark Johnstonreleases, that they are not used together by tools, particularly when a child
536*ef36b3f7SMark Johnstonneeds to refer to a type in the parent.
537*ef36b3f7SMark JohnstonBecause they are linked used the type identifiers, if the wrong parent is used
538*ef36b3f7SMark Johnstonthen the wrong type will be encountered.
53938d120bcSMark Johnston.Lp
54038d120bcSMark JohnstonEach label is encoded in the file format using the following eight byte
54138d120bcSMark Johnstonstructure:
54238d120bcSMark Johnston.Bd -literal
54338d120bcSMark Johnstontypedef struct ctf_lblent {
54438d120bcSMark Johnston	uint_t ctl_label;	/* ref to name of label */
54538d120bcSMark Johnston	uint_t ctl_typeidx;	/* last type associated with this label */
54638d120bcSMark Johnston} ctf_lblent_t;
54738d120bcSMark Johnston.Ed
54838d120bcSMark Johnston.Lp
54938d120bcSMark JohnstonEach label has two different components, a name and a type identifier.
55038d120bcSMark JohnstonThe name is encoded in the
55138d120bcSMark Johnston.Em ctl_label
55238d120bcSMark Johnstonmember which is in the format defined in the section
55338d120bcSMark Johnston.Sx String Identifiers .
55438d120bcSMark JohnstonGenerally, the names of all labels are found in the internal string
55538d120bcSMark Johnstonsection.
55638d120bcSMark Johnston.Lp
55738d120bcSMark JohnstonThe type identifier encoded in the member
55838d120bcSMark Johnston.Em ctl_typeidx
55938d120bcSMark Johnstonrefers to the last type identifier that a label refers to in the current
560*ef36b3f7SMark Johnstonfile.
561*ef36b3f7SMark JohnstonLabels only refer to types in the current file, if the
56238d120bcSMark Johnston.Nm
56338d120bcSMark Johnstonfile is a child, then it will have the same label as its parent;
56438d120bcSMark Johnstonhowever, its label will only refer to its types, not its parents.
56538d120bcSMark Johnston.Lp
56638d120bcSMark JohnstonIt is also possible, though rather uncommon, for a
56738d120bcSMark Johnston.Nm
568*ef36b3f7SMark Johnstonfile to have multiple labels.
569*ef36b3f7SMark JohnstonLabels are placed one after another, every eight bytes.
570*ef36b3f7SMark JohnstonWhen multiple labels are present, types may only belong to a single label.
57138d120bcSMark Johnston.Ss The Object Section
57238d120bcSMark JohnstonThe object section provides a mapping from ELF symbols of type
57338d120bcSMark Johnston.Sy STT_OBJECT
574*ef36b3f7SMark Johnstonin the symbol table to a type identifier.
575*ef36b3f7SMark JohnstonEvery entry in this section is a
57638d120bcSMark Johnston.Sy uint16_t
57738d120bcSMark Johnstonwhich contains a type identifier as described in the section
57838d120bcSMark Johnston.Sx Type Identifiers .
57938d120bcSMark JohnstonIf there is no information for an object, then the type identifier 0x0
58038d120bcSMark Johnstonis stored for that entry.
58138d120bcSMark Johnston.Lp
58238d120bcSMark JohnstonTo walk the object section, you need to have a corresponding
58338d120bcSMark Johnston.Sy symbol table
58438d120bcSMark Johnstonin the ELF object that contains the
58538d120bcSMark Johnston.Nm
586*ef36b3f7SMark Johnstondata.
587*ef36b3f7SMark JohnstonNot every object is included in this section.
588*ef36b3f7SMark JohnstonSpecifically, when walking the symbol table.
589*ef36b3f7SMark JohnstonAn entry is skipped if it matches any of the following conditions:
59038d120bcSMark Johnston.Lp
59138d120bcSMark Johnston.Bl -bullet -offset indent -compact
59238d120bcSMark Johnston.It
59338d120bcSMark JohnstonThe symbol type is not
59438d120bcSMark Johnston.Sy STT_OBJECT
59538d120bcSMark Johnston.It
59638d120bcSMark JohnstonThe symbol's section index is
59738d120bcSMark Johnston.Sy SHN_UNDEF
59838d120bcSMark Johnston.It
59938d120bcSMark JohnstonThe symbol's name offset is zero
60038d120bcSMark Johnston.It
60138d120bcSMark JohnstonThe symbol's section index is
60238d120bcSMark Johnston.Sy SHN_ABS
60338d120bcSMark Johnstonand the value of the symbol is zero.
60438d120bcSMark Johnston.It
60538d120bcSMark JohnstonThe symbol's name is
60638d120bcSMark Johnston.Li _START_
60738d120bcSMark Johnstonor
60838d120bcSMark Johnston.Li _END_ .
60938d120bcSMark JohnstonThese are skipped because they are used for scoping local symbols in
61038d120bcSMark JohnstonELF.
61138d120bcSMark Johnston.El
61238d120bcSMark Johnston.Lp
61338d120bcSMark JohnstonThe following sample code shows an example of iterating the object
61438d120bcSMark Johnstonsection and skipping the correct symbols:
61538d120bcSMark Johnston.Bd -literal
61638d120bcSMark Johnston#include <gelf.h>
61738d120bcSMark Johnston#include <stdio.h>
61838d120bcSMark Johnston
61938d120bcSMark Johnston/*
62038d120bcSMark Johnston * Given the start of the object section in the CTF file, the number of symbols,
62138d120bcSMark Johnston * and the ELF Data sections for the symbol table and the string table, this
62238d120bcSMark Johnston * prints the type identifiers that correspond to objects. Note, a more robust
62338d120bcSMark Johnston * implementation should ensure that they don't walk beyond the end of the CTF
62438d120bcSMark Johnston * object section.
62538d120bcSMark Johnston */
62638d120bcSMark Johnstonstatic int
62738d120bcSMark Johnstonwalk_symbols(uint16_t *objtoff, Elf_Data *symdata, Elf_Data *strdata,
62838d120bcSMark Johnston    long nsyms)
62938d120bcSMark Johnston{
63038d120bcSMark Johnston	long i;
63138d120bcSMark Johnston	uintptr_t strbase = strdata->d_buf;
63238d120bcSMark Johnston
63338d120bcSMark Johnston	for (i = 1; i < nsyms; i++, objftoff++) {
63438d120bcSMark Johnston		const char *name;
63538d120bcSMark Johnston		GElf_Sym sym;
63638d120bcSMark Johnston
63738d120bcSMark Johnston		if (gelf_getsym(symdata, i, &sym) == NULL)
63838d120bcSMark Johnston			return (1);
63938d120bcSMark Johnston
64038d120bcSMark Johnston		if (GELF_ST_TYPE(sym.st_info) != STT_OBJECT)
64138d120bcSMark Johnston			continue;
64238d120bcSMark Johnston		if (sym.st_shndx == SHN_UNDEF || sym.st_name == 0)
64338d120bcSMark Johnston			continue;
64438d120bcSMark Johnston		if (sym.st_shndx == SHN_ABS && sym.st_value == 0)
64538d120bcSMark Johnston			continue;
64638d120bcSMark Johnston		name = (const char *)(strbase + sym.st_name);
64738d120bcSMark Johnston		if (strcmp(name, "_START_") == 0 || strcmp(name, "_END_") == 0)
64838d120bcSMark Johnston			continue;
64938d120bcSMark Johnston
65038d120bcSMark Johnston		(void) printf("Symbol %d has type %d\n", i, *objtoff);
65138d120bcSMark Johnston	}
65238d120bcSMark Johnston
65338d120bcSMark Johnston	return (0);
65438d120bcSMark Johnston}
65538d120bcSMark Johnston.Ed
65638d120bcSMark Johnston.Ss The Function Section
65738d120bcSMark JohnstonThe function section of the
65838d120bcSMark Johnston.Nm
65938d120bcSMark Johnstonfile encodes the types of both the function's arguments and the function's
660*ef36b3f7SMark Johnstonreturn type.
661*ef36b3f7SMark JohnstonSimilar to
66238d120bcSMark Johnston.Sx The Object Section ,
66338d120bcSMark Johnstonthe function section encodes information for all symbols of type
66438d120bcSMark Johnston.Sy STT_FUNCTION ,
665*ef36b3f7SMark Johnstonexcepting those that fit specific criteria.
666*ef36b3f7SMark JohnstonUnlike with objects, because functions have a variable number of arguments, they
667*ef36b3f7SMark Johnstonstart with a type encoding as defined in
66838d120bcSMark Johnston.Sx Type Encoding ,
66938d120bcSMark Johnstonwhich is the size of a
67038d120bcSMark Johnston.Sy uint16_t .
67138d120bcSMark JohnstonFor functions which have no type information available, they are encoded as
67238d120bcSMark Johnston.Li CTF_TYPE_INFO(CTF_K_UNKNOWN, 0, 0) .
673*ef36b3f7SMark JohnstonFunctions with arguments are encoded differently.
674*ef36b3f7SMark JohnstonHere, the variable length is turned into the number of arguments in the
675*ef36b3f7SMark Johnstonfunction.
676*ef36b3f7SMark JohnstonIf a function is a
67738d120bcSMark Johnston.Sy varargs
678*ef36b3f7SMark Johnstontype function, then the number of arguments is increased by one.
679*ef36b3f7SMark JohnstonFunctions with type information are encoded as:
68038d120bcSMark Johnston.Li CTF_TYPE_INFO(CTF_K_FUNCTION, 0, nargs) .
68138d120bcSMark Johnston.Lp
68238d120bcSMark JohnstonFor functions that have no type information, nothing else is encoded, and the
683*ef36b3f7SMark Johnstonnext function is encoded.
684*ef36b3f7SMark JohnstonFor functions with type information, the next
68538d120bcSMark Johnston.Sy uint16_t
686*ef36b3f7SMark Johnstonis encoded with the type identifier of the return type of the function.
687*ef36b3f7SMark JohnstonIt is followed by each of the type identifiers of the arguments, if any exist,
688*ef36b3f7SMark Johnstonin the order that they appear in the function.
689*ef36b3f7SMark JohnstonTherefore, argument 0 is the first type identifier and so on.
690*ef36b3f7SMark JohnstonWhen a function has a final varargs argument, that is encoded with the type
691*ef36b3f7SMark Johnstonidentifier of zero.
69238d120bcSMark Johnston.Lp
69338d120bcSMark JohnstonLike
69438d120bcSMark Johnston.Sx The Object Section ,
695*ef36b3f7SMark Johnstonthe function section is encoded in the order of the symbol table.
696*ef36b3f7SMark JohnstonIt has similar, but slightly different considerations from objects.
697*ef36b3f7SMark JohnstonWhile iterating the symbol table, if any of the following conditions are true,
698*ef36b3f7SMark Johnstonthen the entry is skipped and no corresponding entry is written:
69938d120bcSMark Johnston.Lp
70038d120bcSMark Johnston.Bl -bullet -offset indent -compact
70138d120bcSMark Johnston.It
70238d120bcSMark JohnstonThe symbol type is not
70338d120bcSMark Johnston.Sy STT_FUNCTION
70438d120bcSMark Johnston.It
70538d120bcSMark JohnstonThe symbol's section index is
70638d120bcSMark Johnston.Sy SHN_UNDEF
70738d120bcSMark Johnston.It
70838d120bcSMark JohnstonThe symbol's name offset is zero
70938d120bcSMark Johnston.It
71038d120bcSMark JohnstonThe symbol's name is
71138d120bcSMark Johnston.Li _START_
71238d120bcSMark Johnstonor
71338d120bcSMark Johnston.Li _END_ .
71438d120bcSMark JohnstonThese are skipped because they are used for scoping local symbols in
71538d120bcSMark JohnstonELF.
71638d120bcSMark Johnston.El
71738d120bcSMark Johnston.Ss The Type Section
71838d120bcSMark JohnstonThe type section is the heart of the
71938d120bcSMark Johnston.Nm
720*ef36b3f7SMark Johnstondata.
721*ef36b3f7SMark JohnstonIt encodes all of the information about the types themselves.
722*ef36b3f7SMark JohnstonThe base of the type information comes in two forms, a short form and a long
723*ef36b3f7SMark Johnstonform, each of which may be followed by a variable number of arguments.
724*ef36b3f7SMark JohnstonThe following definitions describe the short and long forms:
72538d120bcSMark Johnston.Bd -literal
72638d120bcSMark Johnston#define	CTF_MAX_SIZE	0xfffe	/* max size of a type in bytes */
72738d120bcSMark Johnston#define	CTF_LSIZE_SENT	0xffff	/* sentinel for ctt_size */
72838d120bcSMark Johnston#define	CTF_MAX_LSIZE	UINT64_MAX
72938d120bcSMark Johnston
73038d120bcSMark Johnstontypedef struct ctf_stype {
73138d120bcSMark Johnston	uint_t ctt_name;	/* reference to name in string table */
73238d120bcSMark Johnston	ushort_t ctt_info;	/* encoded kind, variant length */
73338d120bcSMark Johnston	union {
73438d120bcSMark Johnston		ushort_t _size;	/* size of entire type in bytes */
73538d120bcSMark Johnston		ushort_t _type;	/* reference to another type */
73638d120bcSMark Johnston	} _u;
73738d120bcSMark Johnston} ctf_stype_t;
73838d120bcSMark Johnston
73938d120bcSMark Johnstontypedef struct ctf_type {
74038d120bcSMark Johnston	uint_t ctt_name;	/* reference to name in string table */
74138d120bcSMark Johnston	ushort_t ctt_info;	/* encoded kind, variant length */
74238d120bcSMark Johnston	union {
74338d120bcSMark Johnston		ushort_t _size;	/* always CTF_LSIZE_SENT */
74438d120bcSMark Johnston		ushort_t _type; /* do not use */
74538d120bcSMark Johnston	} _u;
74638d120bcSMark Johnston	uint_t ctt_lsizehi;	/* high 32 bits of type size in bytes */
74738d120bcSMark Johnston	uint_t ctt_lsizelo;	/* low 32 bits of type size in bytes */
74838d120bcSMark Johnston} ctf_type_t;
74938d120bcSMark Johnston
75038d120bcSMark Johnston#define	ctt_size _u._size	/* for fundamental types that have a size */
75138d120bcSMark Johnston#define	ctt_type _u._type	/* for types that reference another type */
75238d120bcSMark Johnston.Ed
75338d120bcSMark Johnston.Pp
75438d120bcSMark JohnstonType sizes are stored in
75538d120bcSMark Johnston.Sy bytes .
75638d120bcSMark JohnstonThe basic small form uses a
75738d120bcSMark Johnston.Sy ushort_t
758*ef36b3f7SMark Johnstonto store the number of bytes.
759*ef36b3f7SMark JohnstonIf the number of bytes in a structure would exceed 0xfffe, then the alternate
760*ef36b3f7SMark Johnstonform, the
76138d120bcSMark Johnston.Sy ctf_type_t ,
762*ef36b3f7SMark Johnstonis used instead.
763*ef36b3f7SMark JohnstonTo indicate that the larger form is being used, the member
76438d120bcSMark Johnston.Em ctt_size
76538d120bcSMark Johnstonis set to value of
76638d120bcSMark Johnston.Sy CTF_LSIZE_SENT
767*ef36b3f7SMark Johnston(0xffff).
768*ef36b3f7SMark JohnstonIn general, when going through the type section, consumers use the
76938d120bcSMark Johnston.Sy ctf_type_t
77038d120bcSMark Johnstonstructure, but pay attention to the value of the member
77138d120bcSMark Johnston.Em ctt_size
77238d120bcSMark Johnstonto determine whether they should increment their scan by the size of the
77338d120bcSMark Johnston.Sy ctf_stype_t
77438d120bcSMark Johnstonor
77538d120bcSMark Johnston.Sy ctf_type_t .
77638d120bcSMark JohnstonNot all kinds of types use
77738d120bcSMark Johnston.Sy ctt_size .
77838d120bcSMark JohnstonThose which do not, will always use the
77938d120bcSMark Johnston.Sy ctf_stype_t
780*ef36b3f7SMark Johnstonstructure.
781*ef36b3f7SMark JohnstonThe individual sections for each kind have more information.
78238d120bcSMark Johnston.Lp
783*ef36b3f7SMark JohnstonTypes are written out in order.
784*ef36b3f7SMark JohnstonTherefore the first entry encountered has a type id of 0x1, or 0x8000 if a
785*ef36b3f7SMark Johnstonchild.
786*ef36b3f7SMark JohnstonThe member
78738d120bcSMark Johnston.Em ctt_name
78838d120bcSMark Johnstonis encoded as described in the section
78938d120bcSMark Johnston.Sx String Identifiers .
790*ef36b3f7SMark JohnstonThe string that it points to is the name of the type.
791*ef36b3f7SMark JohnstonIf the identifier points to an empty string (one that consists solely of a null
792*ef36b3f7SMark Johnstonterminator) then the type does not have a name, this is common with anonymous
793*ef36b3f7SMark Johnstonstructures and unions that only have a typedef to name them, as well as,
794*ef36b3f7SMark Johnstonpointers and qualifiers.
79538d120bcSMark Johnston.Lp
79638d120bcSMark JohnstonThe next member, the
79738d120bcSMark Johnston.Em ctt_info ,
79838d120bcSMark Johnstonis encoded as described in the section
79938d120bcSMark Johnston.Sx Type Encoding .
80038d120bcSMark JohnstonThe types kind tells us how to interpret the remaining data in the
80138d120bcSMark Johnston.Sy ctf_type_t
802*ef36b3f7SMark Johnstonand any variable length data that may exist.
803*ef36b3f7SMark JohnstonThe rest of this section will be broken down into the interpretation of the
804*ef36b3f7SMark Johnstonvarious kinds.
80538d120bcSMark Johnston.Ss Encoding of Integers
80638d120bcSMark JohnstonIntegers, which are of type
80738d120bcSMark Johnston.Sy CTF_K_INTEGER ,
808*ef36b3f7SMark Johnstonhave no variable length arguments.
809*ef36b3f7SMark JohnstonInstead, they are followed by a four byte
81038d120bcSMark Johnston.Sy uint_t
811*ef36b3f7SMark Johnstonwhich describes their encoding.
812*ef36b3f7SMark JohnstonAll integers must be encoded with a variable length of zero.
813*ef36b3f7SMark JohnstonThe
81438d120bcSMark Johnston.Em ctt_size
815*ef36b3f7SMark Johnstonmember describes the length of the integer in bytes.
816*ef36b3f7SMark JohnstonIn general, integer sizes will be rounded up to the closest power of two.
81738d120bcSMark Johnston.Lp
81838d120bcSMark JohnstonThe integer encoding contains three different pieces of information:
81938d120bcSMark Johnston.Bl -bullet -offset indent -compact
82038d120bcSMark Johnston.It
82138d120bcSMark JohnstonThe encoding of the integer
82238d120bcSMark Johnston.It
82338d120bcSMark JohnstonThe offset in
82438d120bcSMark Johnston.Sy bits
82538d120bcSMark Johnstonof the type
82638d120bcSMark Johnston.It
82738d120bcSMark JohnstonThe size in
82838d120bcSMark Johnston.Sy bits
82938d120bcSMark Johnstonof the type
83038d120bcSMark Johnston.El
83138d120bcSMark Johnston.Pp
83238d120bcSMark JohnstonThis encoding can be expressed through the following macros:
83338d120bcSMark Johnston.Bd -literal -offset indent
83438d120bcSMark Johnston#define	CTF_INT_ENCODING(data)	(((data) & 0xff000000) >> 24)
83538d120bcSMark Johnston#define	CTF_INT_OFFSET(data)	(((data) & 0x00ff0000) >> 16)
83638d120bcSMark Johnston#define	CTF_INT_BITS(data)	(((data) & 0x0000ffff))
83738d120bcSMark Johnston
83838d120bcSMark Johnston#define	CTF_INT_DATA(encoding, offset, bits) \\
83938d120bcSMark Johnston	(((encoding) << 24) | ((offset) << 16) | (bits))
84038d120bcSMark Johnston.Ed
84138d120bcSMark Johnston.Pp
84238d120bcSMark JohnstonThe following flags are defined for the encoding at this time:
84338d120bcSMark Johnston.Bd -literal -offset indent
84438d120bcSMark Johnston#define	CTF_INT_SIGNED		0x01
84538d120bcSMark Johnston#define	CTF_INT_CHAR		0x02
84638d120bcSMark Johnston#define	CTF_INT_BOOL		0x04
84738d120bcSMark Johnston#define	CTF_INT_VARARGS		0x08
84838d120bcSMark Johnston.Ed
84938d120bcSMark Johnston.Lp
85038d120bcSMark JohnstonBy default, an integer is considered to be unsigned, unless it has the
85138d120bcSMark Johnston.Sy CTF_INT_SIGNED
852*ef36b3f7SMark Johnstonflag set.
853*ef36b3f7SMark JohnstonIf the flag
85438d120bcSMark Johnston.Sy CTF_INT_CHAR
85538d120bcSMark Johnstonis set, that indicates that the integer is of a type that stores character
85638d120bcSMark Johnstondata, for example the intrinsic C type
85738d120bcSMark Johnston.Sy char
85838d120bcSMark Johnstonwould have the
85938d120bcSMark Johnston.Sy CTF_INT_CHAR
860*ef36b3f7SMark Johnstonflag set.
861*ef36b3f7SMark JohnstonIf the flag
86238d120bcSMark Johnston.Sy CTF_INT_BOOL
863*ef36b3f7SMark Johnstonis set, that indicates that the integer represents a boolean type.
864*ef36b3f7SMark JohnstonFor example, the intrinsic C type
86538d120bcSMark Johnston.Sy _Bool
86638d120bcSMark Johnstonwould have the
86738d120bcSMark Johnston.Sy CTF_INT_BOOL
868*ef36b3f7SMark Johnstonflag set.
869*ef36b3f7SMark JohnstonFinally, the flag
87038d120bcSMark Johnston.Sy CTF_INT_VARARGS
87138d120bcSMark Johnstonindicates that the integer is used as part of a variable number of arguments.
87238d120bcSMark JohnstonThis encoding is rather uncommon.
87338d120bcSMark Johnston.Ss Encoding of Floats
87438d120bcSMark JohnstonFloats, which are of type
87538d120bcSMark Johnston.Sy CTF_K_FLOAT ,
876*ef36b3f7SMark Johnstonare similar to their integer counterparts.
877*ef36b3f7SMark JohnstonThey have no variable length arguments and are followed by a four byte encoding
878*ef36b3f7SMark Johnstonwhich describes the kind of float that exists.
879*ef36b3f7SMark JohnstonThe
88038d120bcSMark Johnston.Em ctt_size
881*ef36b3f7SMark Johnstonmember is the size, in bytes, of the float.
882*ef36b3f7SMark JohnstonThe float encoding has three different pieces of information inside of it:
88338d120bcSMark Johnston.Lp
88438d120bcSMark Johnston.Bl -bullet -offset indent -compact
88538d120bcSMark Johnston.It
88638d120bcSMark JohnstonThe specific kind of float that exists
88738d120bcSMark Johnston.It
88838d120bcSMark JohnstonThe offset in
88938d120bcSMark Johnston.Sy bits
89038d120bcSMark Johnstonof the float
89138d120bcSMark Johnston.It
89238d120bcSMark JohnstonThe size in
89338d120bcSMark Johnston.Sy bits
89438d120bcSMark Johnstonof the float
89538d120bcSMark Johnston.El
89638d120bcSMark Johnston.Lp
89738d120bcSMark JohnstonThis encoding can be expressed through the following macros:
89838d120bcSMark Johnston.Bd -literal -offset indent
89938d120bcSMark Johnston#define	CTF_FP_ENCODING(data)	(((data) & 0xff000000) >> 24)
90038d120bcSMark Johnston#define	CTF_FP_OFFSET(data)	(((data) & 0x00ff0000) >> 16)
90138d120bcSMark Johnston#define	CTF_FP_BITS(data)	(((data) & 0x0000ffff))
90238d120bcSMark Johnston
90338d120bcSMark Johnston#define	CTF_FP_DATA(encoding, offset, bits) \\
90438d120bcSMark Johnston	(((encoding) << 24) | ((offset) << 16) | (bits))
90538d120bcSMark Johnston.Ed
90638d120bcSMark Johnston.Lp
90738d120bcSMark JohnstonWhere as the encoding for integers was a series of flags, the encoding for
908*ef36b3f7SMark Johnstonfloats maps to a specific kind of float.
909*ef36b3f7SMark JohnstonIt is not a flag-based value.
910*ef36b3f7SMark JohnstonThe kinds of floats correspond to both their size, and the encoding.
911*ef36b3f7SMark JohnstonThis covers all of the basic C intrinsic floating point types.
912*ef36b3f7SMark JohnstonThe following are the different kinds of floats represented in the encoding:
91338d120bcSMark Johnston.Bd -literal -offset indent
91438d120bcSMark Johnston#define	CTF_FP_SINGLE	1	/* IEEE 32-bit float encoding */
91538d120bcSMark Johnston#define	CTF_FP_DOUBLE	2	/* IEEE 64-bit float encoding */
91638d120bcSMark Johnston#define	CTF_FP_CPLX	3	/* Complex encoding */
91738d120bcSMark Johnston#define	CTF_FP_DCPLX	4	/* Double complex encoding */
91838d120bcSMark Johnston#define	CTF_FP_LDCPLX	5	/* Long double complex encoding */
91938d120bcSMark Johnston#define	CTF_FP_LDOUBLE	6	/* Long double encoding */
92038d120bcSMark Johnston#define	CTF_FP_INTRVL	7	/* Interval (2x32-bit) encoding */
92138d120bcSMark Johnston#define	CTF_FP_DINTRVL	8	/* Double interval (2x64-bit) encoding */
92238d120bcSMark Johnston#define	CTF_FP_LDINTRVL	9	/* Long double interval (2x128-bit) encoding */
92338d120bcSMark Johnston#define	CTF_FP_IMAGRY	10	/* Imaginary (32-bit) encoding */
92438d120bcSMark Johnston#define	CTF_FP_DIMAGRY	11	/* Long imaginary (64-bit) encoding */
92538d120bcSMark Johnston#define	CTF_FP_LDIMAGRY	12	/* Long double imaginary (128-bit) encoding */
92638d120bcSMark Johnston.Ed
92738d120bcSMark Johnston.Ss Encoding of Arrays
92838d120bcSMark JohnstonArrays, which are of type
92938d120bcSMark Johnston.Sy CTF_K_ARRAY ,
930*ef36b3f7SMark Johnstonhave no variable length arguments.
931*ef36b3f7SMark JohnstonThey are followed by a structure which describes the number of elements in the
932*ef36b3f7SMark Johnstonarray, the type identifier of the elements in the array, and the type identifier
933*ef36b3f7SMark Johnstonof the index of the array.
934*ef36b3f7SMark JohnstonWith arrays, the
93538d120bcSMark Johnston.Em ctt_size
936*ef36b3f7SMark Johnstonmember is set to zero.
937*ef36b3f7SMark JohnstonThe structure that follows an array is defined as:
93838d120bcSMark Johnston.Bd -literal
93938d120bcSMark Johnstontypedef struct ctf_array {
94038d120bcSMark Johnston	ushort_t cta_contents;	/* reference to type of array contents */
94138d120bcSMark Johnston	ushort_t cta_index;	/* reference to type of array index */
94238d120bcSMark Johnston	uint_t cta_nelems;	/* number of elements */
94338d120bcSMark Johnston} ctf_array_t;
94438d120bcSMark Johnston.Ed
94538d120bcSMark Johnston.Lp
94638d120bcSMark JohnstonThe
94738d120bcSMark Johnston.Em cta_contents
94838d120bcSMark Johnstonand
94938d120bcSMark Johnston.Em cta_index
95038d120bcSMark Johnstonmembers of the
95138d120bcSMark Johnston.Sy ctf_array_t
95238d120bcSMark Johnstonare type identifiers which are encoded as per the section
95338d120bcSMark Johnston.Sx Type Identifiers .
95438d120bcSMark JohnstonThe member
95538d120bcSMark Johnston.Em cta_nelems
956*ef36b3f7SMark Johnstonis a simple four byte unsigned count of the number of elements.
957*ef36b3f7SMark JohnstonThis count may be zero when encountering C99's flexible array members.
95838d120bcSMark Johnston.Ss Encoding of Functions
95938d120bcSMark JohnstonFunction types, which are of type
96038d120bcSMark Johnston.Sy CTF_K_FUNCTION ,
961*ef36b3f7SMark Johnstonuse the variable length list to be the number of arguments in the function.
962*ef36b3f7SMark JohnstonWhen the function has a final member which is a varargs, then the argument count
963*ef36b3f7SMark Johnstonis incremented by one to account for the variable argument.
964*ef36b3f7SMark JohnstonHere, the
96538d120bcSMark Johnston.Em ctt_type
96638d120bcSMark Johnstonmember is encoded with the type identifier of the return type of the function.
96738d120bcSMark JohnstonNote that the
96838d120bcSMark Johnston.Em ctt_size
96938d120bcSMark Johnstonmember is not used here.
97038d120bcSMark Johnston.Lp
97138d120bcSMark JohnstonThe variable argument list contains the type identifiers for the arguments of
972*ef36b3f7SMark Johnstonthe function, if any.
973*ef36b3f7SMark JohnstonEach one is represented by a
97438d120bcSMark Johnston.Sy uint16_t
97538d120bcSMark Johnstonand encoded according to the
97638d120bcSMark Johnston.Sx Type Identifiers
977*ef36b3f7SMark Johnstonsection.
978*ef36b3f7SMark JohnstonIf the function's last argument is of type varargs, then it is also written out,
979*ef36b3f7SMark Johnstonbut the type identifier is zero.
980*ef36b3f7SMark JohnstonThis is included in the count of the function's arguments.
98138d120bcSMark Johnston.Ss Encoding of Structures and Unions
98238d120bcSMark JohnstonStructures and Unions, which are encoded with
98338d120bcSMark Johnston.Sy CTF_K_STRUCT
98438d120bcSMark Johnstonand
98538d120bcSMark Johnston.Sy CTF_K_UNION
986*ef36b3f7SMark Johnstonrespectively,  are very similar constructs in C.
987*ef36b3f7SMark JohnstonThe main difference between them is the fact that every member of a structure
988*ef36b3f7SMark Johnstonfollows one another, where as in a union, all members share the same memory.
989*ef36b3f7SMark JohnstonThey are also very similar in terms of their encoding in
99038d120bcSMark Johnston.Nm .
99138d120bcSMark JohnstonThe variable length argument for structures and unions represents the number of
992*ef36b3f7SMark Johnstonmembers that they have.
993*ef36b3f7SMark JohnstonThe value of the member
99438d120bcSMark Johnston.Em ctt_size
995*ef36b3f7SMark Johnstonis the size of the structure and union.
996*ef36b3f7SMark JohnstonThere are two different structures which are used to encode members in the
997*ef36b3f7SMark Johnstonvariable list.
998*ef36b3f7SMark JohnstonWhen the size of a structure or union is greater than or equal to the large
999*ef36b3f7SMark Johnstonmember threshold, 8192, then a different structure is used to encode the member,
1000*ef36b3f7SMark Johnstonall members are encoded using the same structure.
1001*ef36b3f7SMark JohnstonThe structure for members is as follows:
100238d120bcSMark Johnston.Bd -literal
100338d120bcSMark Johnstontypedef struct ctf_member {
100438d120bcSMark Johnston	uint_t ctm_name;	/* reference to name in string table */
100538d120bcSMark Johnston	ushort_t ctm_type;	/* reference to type of member */
100638d120bcSMark Johnston	ushort_t ctm_offset;	/* offset of this member in bits */
100738d120bcSMark Johnston} ctf_member_t;
100838d120bcSMark Johnston
100938d120bcSMark Johnstontypedef struct ctf_lmember {
101038d120bcSMark Johnston	uint_t ctlm_name;	/* reference to name in string table */
101138d120bcSMark Johnston	ushort_t ctlm_type;	/* reference to type of member */
101238d120bcSMark Johnston	ushort_t ctlm_pad;	/* padding */
101338d120bcSMark Johnston	uint_t ctlm_offsethi;	/* high 32 bits of member offset in bits */
101438d120bcSMark Johnston	uint_t ctlm_offsetlo;	/* low 32 bits of member offset in bits */
101538d120bcSMark Johnston} ctf_lmember_t;
101638d120bcSMark Johnston.Ed
101738d120bcSMark Johnston.Lp
101838d120bcSMark JohnstonBoth the
101938d120bcSMark Johnston.Em ctm_name
102038d120bcSMark Johnstonand
102138d120bcSMark Johnston.Em ctlm_name
1022*ef36b3f7SMark Johnstonrefer to the name of the member.
1023*ef36b3f7SMark JohnstonThe name is encoded as an offset into the string table as described by the
1024*ef36b3f7SMark Johnstonsection
102538d120bcSMark Johnston.Sx String Identifiers .
102638d120bcSMark JohnstonThe members
102738d120bcSMark Johnston.Sy ctm_type
102838d120bcSMark Johnstonand
102938d120bcSMark Johnston.Sy ctlm_type
1030*ef36b3f7SMark Johnstonboth refer to the type of the member.
1031*ef36b3f7SMark JohnstonThey are encoded as per the section
103238d120bcSMark Johnston.Sx Type Identifiers .
103338d120bcSMark Johnston.Lp
103438d120bcSMark JohnstonThe last piece of information that is present is the offset which describes the
1035*ef36b3f7SMark Johnstonoffset in memory that the member begins at.
1036*ef36b3f7SMark JohnstonFor unions, this value will always be zero because the start of unions in memory
1037*ef36b3f7SMark Johnstonis always zero.
1038*ef36b3f7SMark JohnstonFor structures, this is the offset in
103938d120bcSMark Johnston.Sy bits
1040*ef36b3f7SMark Johnstonthat the member begins at.
1041*ef36b3f7SMark JohnstonNote that a compiler may lay out a type with padding.
104238d120bcSMark JohnstonThis means that the difference in offset between two consecutive members may be
1043*ef36b3f7SMark Johnstonlarger than the size of the member.
1044*ef36b3f7SMark JohnstonWhen the size of the overall structure is strictly less than 8192 bytes, the
1045*ef36b3f7SMark Johnstonnormal structure,
104638d120bcSMark Johnston.Sy ctf_member_t ,
104738d120bcSMark Johnstonis used and the offset in bits is stored in the member
104838d120bcSMark Johnston.Em ctm_offset .
104938d120bcSMark JohnstonHowever, when the size of the structure is greater than or equal to 8192 bytes,
1050*ef36b3f7SMark Johnstonthen the number of bits is split into two 32-bit quantities.
1051*ef36b3f7SMark JohnstonOne member,
105238d120bcSMark Johnston.Em ctlm_offsethi ,
105338d120bcSMark Johnstonrepresents the upper 32 bits of the offset, while the other member,
105438d120bcSMark Johnston.Em ctlm_offsetlo ,
1055*ef36b3f7SMark Johnstonrepresents the lower 32 bits of the offset.
1056*ef36b3f7SMark JohnstonThese can be joined together to get a 64-bit sized offset in bits by shifting
1057*ef36b3f7SMark Johnstonthe member
105838d120bcSMark Johnston.Em ctlm_offsethi
105938d120bcSMark Johnstonto the left by thirty two and then doing a binary or of
106038d120bcSMark Johnston.Em ctlm_offsetlo .
106138d120bcSMark Johnston.Ss Encoding of Enumerations
106238d120bcSMark JohnstonEnumerations, noted by the type
106338d120bcSMark Johnston.Sy CTF_K_ENUM ,
1064*ef36b3f7SMark Johnstonare similar to structures.
1065*ef36b3f7SMark JohnstonEnumerations use the variable list to note the number of values that the
1066*ef36b3f7SMark Johnstonenumeration contains, which we'll term enumerators.
1067*ef36b3f7SMark JohnstonIn C, an enumeration is always equivalent to the intrinsic type
106838d120bcSMark Johnston.Sy int ,
106938d120bcSMark Johnstonthus the value of the member
107038d120bcSMark Johnston.Em ctt_size
107138d120bcSMark Johnstonis always the size of an integer which is determined based on the current model.
107238d120bcSMark JohnstonFor illumos systems, this will always be 4, as an integer is always defined to
107338d120bcSMark Johnstonbe 4 bytes large in both
107438d120bcSMark Johnston.Sy ILP32
107538d120bcSMark Johnstonand
107638d120bcSMark Johnston.Sy LP64 ,
107738d120bcSMark Johnstonregardless of the architecture.
107838d120bcSMark Johnston.Lp
107938d120bcSMark JohnstonThe enumerators encoded in an enumeration have the following structure in the
108038d120bcSMark Johnstonvariable list:
108138d120bcSMark Johnston.Bd -literal
108238d120bcSMark Johnstontypedef struct ctf_enum {
108338d120bcSMark Johnston	uint_t cte_name;	/* reference to name in string table */
108438d120bcSMark Johnston	int cte_value;		/* value associated with this name */
108538d120bcSMark Johnston} ctf_enum_t;
108638d120bcSMark Johnston.Ed
108738d120bcSMark Johnston.Pp
108838d120bcSMark JohnstonThe member
108938d120bcSMark Johnston.Em cte_name
109038d120bcSMark Johnstonrefers to the name of the enumerator's value, it is encoded according to the
109138d120bcSMark Johnstonrules in the section
109238d120bcSMark Johnston.Sx String Identifiers .
109338d120bcSMark JohnstonThe member
109438d120bcSMark Johnston.Em cte_value
109538d120bcSMark Johnstoncontains the integer value of this enumerator.
109638d120bcSMark Johnston.Ss Encoding of Forward References
109738d120bcSMark JohnstonForward references, types of kind
109838d120bcSMark Johnston.Sy CTF_K_FORWARD ,
109938d120bcSMark Johnstonin a
110038d120bcSMark Johnston.Nm
1101*ef36b3f7SMark Johnstonfile refer to types which may not have a definition at all, only a name.
1102*ef36b3f7SMark JohnstonIf the
110338d120bcSMark Johnston.Nm
110438d120bcSMark Johnstonfile is a child, then it may be that the forward is resolved to an
110538d120bcSMark Johnstonactual type in the parent, otherwise the definition may be in another
110638d120bcSMark Johnston.Nm
1107*ef36b3f7SMark Johnstoncontainer or may not be known at all.
1108*ef36b3f7SMark JohnstonThe only member of the
110938d120bcSMark Johnston.Sy ctf_type_t
111038d120bcSMark Johnstonthat matters for a forward declaration is the
111138d120bcSMark Johnston.Em ctt_name
111238d120bcSMark Johnstonwhich points to the name of the forward reference in the string table as
1113*ef36b3f7SMark Johnstondescribed earlier.
1114*ef36b3f7SMark JohnstonThere is no other information recorded for forward references.
111538d120bcSMark Johnston.Ss Encoding of Pointers, Typedefs, Volatile, Const, and Restrict
111638d120bcSMark JohnstonPointers, typedefs, volatile, const, and restrict are all similar in
111738d120bcSMark Johnston.Nm .
1118*ef36b3f7SMark JohnstonThey all refer to another type.
1119*ef36b3f7SMark JohnstonIn the case of typedefs, they provide an alternate name, while volatile, const,
1120*ef36b3f7SMark Johnstonand restrict change how the type is interpreted in the C programming language.
1121*ef36b3f7SMark JohnstonThis covers the
112238d120bcSMark Johnston.Nm
112338d120bcSMark Johnstonkinds
112438d120bcSMark Johnston.Sy CTF_K_POINTER ,
112538d120bcSMark Johnston.Sy CTF_K_TYPEDEF ,
112638d120bcSMark Johnston.Sy CTF_K_VOLATILE ,
112738d120bcSMark Johnston.Sy CTF_K_RESTRICT ,
112838d120bcSMark Johnstonand
112938d120bcSMark Johnston.Sy CTF_K_CONST .
113038d120bcSMark Johnston.Lp
113138d120bcSMark JohnstonThese types have no variable list entries and use the member
113238d120bcSMark Johnston.Em ctt_type
113338d120bcSMark Johnstonto refer to the base type that they modify.
113438d120bcSMark Johnston.Ss Encoding of Unknown Types
113538d120bcSMark JohnstonTypes with the kind
113638d120bcSMark Johnston.Sy CTF_K_UNKNOWN
1137*ef36b3f7SMark Johnstonare used to indicate gaps in the type identifier space.
1138*ef36b3f7SMark JohnstonThese entries consume an identifier, but do not define anything.
1139*ef36b3f7SMark JohnstonNothing should refer to these gap identifiers.
114038d120bcSMark Johnston.Ss Dependencies Between Types
1141*ef36b3f7SMark JohnstonC types can be imagined as a directed, cyclic, graph.
1142*ef36b3f7SMark JohnstonStructures and unions may refer to each other in a way that creates a cyclic
1143*ef36b3f7SMark Johnstondependency.
1144*ef36b3f7SMark JohnstonIn cases such as these, the entire type section must be read in and processed.
1145*ef36b3f7SMark JohnstonConsumers must not assume that every type can be laid out in dependency order;
1146*ef36b3f7SMark Johnstonthey cannot.
114738d120bcSMark Johnston.Ss The String Section
114838d120bcSMark JohnstonThe last section of the
114938d120bcSMark Johnston.Nm
115038d120bcSMark Johnstonfile is the
115138d120bcSMark Johnston.Sy string
1152*ef36b3f7SMark Johnstonsection.
1153*ef36b3f7SMark JohnstonThis section encodes all of the strings that appear throughout the other
1154*ef36b3f7SMark Johnstonsections.
1155*ef36b3f7SMark JohnstonIt is laid out as a series of characters followed by a null terminator.
1156*ef36b3f7SMark JohnstonGenerally, all names are written out in ASCII, as most C compilers do not allow
1157*ef36b3f7SMark Johnstonand characters to appear in identifiers outside of a subset of ASCII.
1158*ef36b3f7SMark JohnstonHowever, any extended characters sets should be written out as a series of UTF-8
1159*ef36b3f7SMark Johnstonbytes.
116038d120bcSMark Johnston.Lp
116138d120bcSMark JohnstonThe first entry in the section, at offset zero, is a single null
1162*ef36b3f7SMark Johnstonterminator to reference the empty string.
1163*ef36b3f7SMark JohnstonFollowing that, each C string should be written out, including the null
1164*ef36b3f7SMark Johnstonterminator.
1165*ef36b3f7SMark JohnstonOffsets that refer to something in this section should refer to the first byte
1166*ef36b3f7SMark Johnstonwhich begins a string.
1167*ef36b3f7SMark JohnstonBeyond the first byte in the section being the null terminator, the order of
1168*ef36b3f7SMark Johnstonstrings is unimportant.
1169*ef36b3f7SMark Johnston.Sh Data Encoding and ELF Considerations
117038d120bcSMark Johnston.Nm
117138d120bcSMark Johnstondata is generally included in ELF objects which specify information to
1172*ef36b3f7SMark Johnstonidentify the architecture and endianness of the file.
1173*ef36b3f7SMark JohnstonA
117438d120bcSMark Johnston.Nm
1175*ef36b3f7SMark Johnstoncontainer inside such an object must match the endianness of the ELF object.
1176*ef36b3f7SMark JohnstonAside from the question of the endian encoding of data, there should be no other
1177*ef36b3f7SMark Johnstondifferences between architectures.
1178*ef36b3f7SMark JohnstonWhile many of the types in this document refer to non-fixed size C integral
1179*ef36b3f7SMark Johnstontypes, they are equivalent in the models
118038d120bcSMark Johnston.Sy ILP32
118138d120bcSMark Johnstonand
118238d120bcSMark Johnston.Sy LP64 .
118338d120bcSMark JohnstonIf any other model is being used with
118438d120bcSMark Johnston.Nm
118538d120bcSMark Johnstondata that has different sizes, then it must not use the model's sizes for
118638d120bcSMark Johnstonthose integral types and instead use the fixed size equivalents based on an
118738d120bcSMark Johnston.Sy ILP32
118838d120bcSMark Johnstonenvironment.
118938d120bcSMark Johnston.Lp
119038d120bcSMark JohnstonWhen placing a
119138d120bcSMark Johnston.Nm
119238d120bcSMark Johnstoncontainer inside of an ELF object, there are certain conventions that are
119338d120bcSMark Johnstonexpected for the purposes of tooling being able to find the
119438d120bcSMark Johnston.Nm
1195*ef36b3f7SMark Johnstondata.
1196*ef36b3f7SMark JohnstonIn particular, a given ELF object should only contain a single
119738d120bcSMark Johnston.Nm
1198*ef36b3f7SMark Johnstonsection.
1199*ef36b3f7SMark JohnstonMultiple containers should be merged together into a single one.
120038d120bcSMark Johnston.Lp
120138d120bcSMark JohnstonThe
120238d120bcSMark Johnston.Nm
1203*ef36b3f7SMark Johnstonfile should be included in its own ELF section.
1204*ef36b3f7SMark JohnstonThe section's name must be
120538d120bcSMark Johnston.Ql .SUNW_ctf .
120638d120bcSMark JohnstonThe type of the section must be
120738d120bcSMark Johnston.Sy SHT_PROGBITS .
120838d120bcSMark JohnstonThe section should have a link set to the symbol table and its address
120938d120bcSMark Johnstonalignment must be 4.
121038d120bcSMark Johnston.Sh SEE ALSO
121138d120bcSMark Johnston.Xr dtrace 1 ,
121238d120bcSMark Johnston.Xr elf 3 ,
121338d120bcSMark Johnston.Xr gelf 3 ,
121438d120bcSMark Johnston.Xr a.out 5 ,
121538d120bcSMark Johnston.Xr elf 5
1216