xref: /freebsd-src/cddl/contrib/opensolaris/lib/libctf/common/ctf.5 (revision 7421ff0751fadff2b6f5154f43067b869509603f)
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
42ef36b3f7SMark Johnstonobject.
43ef36b3f7SMark JohnstonThe
4438d120bcSMark Johnston.Nm
4538d120bcSMark Johnstondata may also include information about the types of global objects and
4638d120bcSMark Johnstonthe return type and arguments of functions in the symbol table.
4738d120bcSMark Johnston.Lp
4838d120bcSMark JohnstonBecause a
4938d120bcSMark Johnston.Nm
5038d120bcSMark Johnstonfile is often embedded inside a file, rather than being a standalone
5138d120bcSMark Johnstonfile itself, it may also be referred to as a
5238d120bcSMark Johnston.Nm
5338d120bcSMark Johnston.Sy container .
5438d120bcSMark Johnston.Lp
55*7421ff07SMark JohnstonOn
56*7421ff07SMark Johnston.Fx
57*7421ff07SMark Johnstonsystems,
5838d120bcSMark Johnston.Nm
59*7421ff07SMark Johnstondata is consumed by
60ef36b3f7SMark Johnston.Xr dtrace 1 .
6138d120bcSMark JohnstonProgrammatic access to
6238d120bcSMark Johnston.Nm
63*7421ff07SMark Johnstondata can be obtained through libctf.
6438d120bcSMark Johnston.Lp
6538d120bcSMark JohnstonThe
6638d120bcSMark Johnston.Nm
67ef36b3f7SMark Johnstonfile format is broken down into seven different sections.
68ef36b3f7SMark JohnstonThe first section is the
6938d120bcSMark Johnston.Sy preamble
7038d120bcSMark Johnstonand
7138d120bcSMark Johnston.Sy header ,
7238d120bcSMark Johnstonwhich describes the version of the
7338d120bcSMark Johnston.Nm
74*7421ff07SMark Johnstonfile, the links it has to other
7538d120bcSMark Johnston.Nm
76ef36b3f7SMark Johnstonfiles, and the sizes of the other sections.
77ef36b3f7SMark JohnstonThe next section is the
7838d120bcSMark Johnston.Sy label
7938d120bcSMark Johnstonsection,
8038d120bcSMark Johnstonwhich provides a way of identifying similar groups of
8138d120bcSMark Johnston.Nm
82ef36b3f7SMark Johnstondata across multiple files.
83ef36b3f7SMark JohnstonThis is followed by the
8438d120bcSMark Johnston.Sy object
85*7421ff07SMark Johnstoninformation section, which describes the types of global
86ef36b3f7SMark Johnstonsymbols.
87ef36b3f7SMark JohnstonThe subsequent section is the
8838d120bcSMark Johnston.Sy function
8938d120bcSMark Johnstoninformation section, which describes the return
90ef36b3f7SMark Johnstontypes and arguments of functions.
91ef36b3f7SMark JohnstonThe next section is the
9238d120bcSMark Johnston.Sy type
9338d120bcSMark Johnstoninformation section, which describes
9438d120bcSMark Johnstonthe format and layout of the C types themselves, and finally the last
9538d120bcSMark Johnstonsection is the
9638d120bcSMark Johnston.Sy string
9738d120bcSMark Johnstonsection, which contains the names of types, enumerations, members, and
9838d120bcSMark Johnstonlabels.
9938d120bcSMark Johnston.Lp
10038d120bcSMark JohnstonWhile strictly speaking, only the
10138d120bcSMark Johnston.Sy preamble
10238d120bcSMark Johnstonand
10338d120bcSMark Johnston.Sy header
10438d120bcSMark Johnstonare required, to be actually useful, both the type and string
10538d120bcSMark Johnstonsections are necessary.
10638d120bcSMark Johnston.Lp
10738d120bcSMark JohnstonA
10838d120bcSMark Johnston.Nm
10938d120bcSMark Johnstonfile may contain all of the type information that it requires, or it
11038d120bcSMark Johnstonmay optionally refer to another
11138d120bcSMark Johnston.Nm
112ef36b3f7SMark Johnstonfile which holds the remaining types.
113ef36b3f7SMark JohnstonWhen a
11438d120bcSMark Johnston.Nm
11538d120bcSMark Johnstonfile refers to another file, it is called the
11638d120bcSMark Johnston.Sy child
11738d120bcSMark Johnstonand the file it refers to is called the
11838d120bcSMark Johnston.Sy parent .
119ef36b3f7SMark JohnstonA given file may only refer to one parent.
120ef36b3f7SMark JohnstonThis process is called
12138d120bcSMark Johnston.Em uniquification
12238d120bcSMark Johnstonbecause it ensures each child only has type information that is
123ef36b3f7SMark Johnstonunique to it.
124ef36b3f7SMark JohnstonA common example of this is that most kernel modules in illumos are uniquified
125ef36b3f7SMark Johnstonagainst the kernel module
12638d120bcSMark Johnston.Sy genunix
12738d120bcSMark Johnstonand the type information that comes from the
12838d120bcSMark Johnston.Sy IP
129ef36b3f7SMark Johnstonmodule.
130ef36b3f7SMark JohnstonThis means that a module only has types that are unique to itself and the most
131ef36b3f7SMark Johnstoncommon types in the kernel are not duplicated.
13238d120bcSMark Johnston.Sh FILE FORMAT
13338d120bcSMark JohnstonThis documents version
13438d120bcSMark Johnston.Em two
13538d120bcSMark Johnstonof the
13638d120bcSMark Johnston.Nm
137ef36b3f7SMark Johnstonfile format.
138*7421ff07SMark JohnstonAll applications and tools on
139*7421ff07SMark Johnston.Fx
140*7421ff07SMark Johnstoncurrently 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
247ef36b3f7SMark Johnstonfile which defines the format of the rest of the header.
248ef36b3f7SMark 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
250ef36b3f7SMark Johnstonversion to version.
251ef36b3f7SMark JohnstonThe
25238d120bcSMark Johnston.Em ctp_magic
25338d120bcSMark Johnstonmember defines the magic number for the
25438d120bcSMark Johnston.Nm
255ef36b3f7SMark Johnstonfile format.
256ef36b3f7SMark 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
261ef36b3f7SMark Johnstonfile.
262ef36b3f7SMark JohnstonThe
26338d120bcSMark Johnston.Em ctp_version
26438d120bcSMark Johnstonmember defines the version of the
26538d120bcSMark Johnston.Nm
266ef36b3f7SMark Johnstonfile.
267ef36b3f7SMark JohnstonThe current version is
26838d120bcSMark Johnston.Li 2 .
269ef36b3f7SMark JohnstonIt is possible to encounter an unsupported version.
270ef36b3f7SMark JohnstonIn that case, software should not try to parse the format, as it may have
271ef36b3f7SMark 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
290ef36b3f7SMark Johnstonalgorithm.
291ef36b3f7SMark JohnstonIf this flag is not present, then the body has not been compressed and no
292ef36b3f7SMark Johnstonspecial action is needed to interpret it.
293ef36b3f7SMark 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
303*7421ff07SMark Johnstondenotes whether or not this
30438d120bcSMark Johnston.Nm
30538d120bcSMark Johnstonfile is the child of another
30638d120bcSMark Johnston.Nm
307ef36b3f7SMark Johnstonfile and also indicates the size of the remaining sections.
308ef36b3f7SMark JohnstonThe structure for the
309*7421ff07SMark 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 ,
333ef36b3f7SMark Johnstonare used to identify the parent.
334ef36b3f7SMark JohnstonThe value of both members are offsets into the
33538d120bcSMark Johnston.Sy string
336ef36b3f7SMark Johnstonsection which point to the start of a null-terminated string.
337ef36b3f7SMark 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
340ef36b3f7SMark Johnstonmember.
341ef36b3f7SMark 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
346ef36b3f7SMark Johnstonparent.
347ef36b3f7SMark JohnstonIf
34838d120bcSMark Johnston.Em ctf_parname
34938d120bcSMark Johnstonis set, it is not necessary to define
35038d120bcSMark Johnston.Em cth_parlabel ,
351ef36b3f7SMark Johnstonas the parent may not have a label.
352ef36b3f7SMark 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 )
357ef36b3f7SMark Johnstondescribe the beginning of the corresponding sections.
358ef36b3f7SMark 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
363ef36b3f7SMark Johnstonfile.
364ef36b3f7SMark JohnstonThe difference between members indicates the size of the section itself.
365ef36b3f7SMark JohnstonDifferent offsets have different alignment requirements.
366ef36b3f7SMark 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
374ef36b3f7SMark Johnstonmust be four-byte aligned.
375ef36b3f7SMark JohnstonThe section
37638d120bcSMark Johnston.Em cth_stroff
377ef36b3f7SMark Johnstonhas no alignment requirements.
378ef36b3f7SMark JohnstonTo calculate the size of a given section, excepting the
37938d120bcSMark Johnston.Sy string
380ef36b3f7SMark Johnstonsection, one should subtract the offset of the section from the following one.
381ef36b3f7SMark 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
390ef36b3f7SMark Johnstondescribes the length of the string section itself.
391ef36b3f7SMark 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
402ef36b3f7SMark Johnstondata, types are referred to by identifiers.
403ef36b3f7SMark JohnstonA given
40438d120bcSMark Johnston.Nm
405ef36b3f7SMark Johnstonfile supports up to 32767 (0x7fff) types.
406ef36b3f7SMark 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
427ef36b3f7SMark Johnstonwhich are an offset into a string table.
428ef36b3f7SMark JohnstonThe
42938d120bcSMark Johnston.Nm
43038d120bcSMark Johnstonformat supports two different string tables which have an identifier of
431ef36b3f7SMark Johnstonzero or one.
432ef36b3f7SMark JohnstonThis identifier is stored in the high-order bit of the unsigned four byte
433ef36b3f7SMark Johnstonoffset.
434ef36b3f7SMark 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
438ef36b3f7SMark Johnstonsection in the CTF file itself.
439ef36b3f7SMark JohnstonString table identifier one refers to an external string table which is the ELF
440ef36b3f7SMark 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
460ef36b3f7SMark Johnstonroot type, and 10 bits for the variable length.
461ef36b3f7SMark 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
469ef36b3f7SMark JohnstonThe current version of the file format defines 14 different kinds.
470ef36b3f7SMark 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
474ef36b3f7SMark Johnstonfile.
475ef36b3f7SMark 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
494ef36b3f7SMark Johnstonindirectly because they are part of some other structure.
495ef36b3f7SMark JohnstonThese types that are referenced directly and used are called
49638d120bcSMark Johnston.Sy root
497ef36b3f7SMark Johnstontypes.
498ef36b3f7SMark JohnstonOther types may be used indirectly, for example, a program may reference
499ef36b3f7SMark Johnstona structure directly, but not one of its members which has a type.
500ef36b3f7SMark JohnstonThat type is not considered a
50138d120bcSMark Johnston.Sy root
502ef36b3f7SMark Johnstontype.
503ef36b3f7SMark 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
528ef36b3f7SMark Johnstoncontainers come from the same source base and version.
529ef36b3f7SMark JohnstonFor example, when building illumos, there are many kernel modules that are built
530ef36b3f7SMark Johnstonagainst a single collection of source code.
531ef36b3f7SMark JohnstonA label is encoded into the
53238d120bcSMark Johnston.Nm
533ef36b3f7SMark Johnstonfiles that corresponds with the particular build.
534ef36b3f7SMark JohnstonThis ensures that if files on the system were to become mixed up from multiple
535ef36b3f7SMark Johnstonreleases, that they are not used together by tools, particularly when a child
536ef36b3f7SMark Johnstonneeds to refer to a type in the parent.
537*7421ff07SMark JohnstonBecause they are linked using the type identifiers, if the wrong parent is used
538ef36b3f7SMark 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
560ef36b3f7SMark Johnstonfile.
561ef36b3f7SMark 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;
564*7421ff07SMark Johnstonhowever, its label will only refer to its types, not its parent's.
56538d120bcSMark Johnston.Lp
56638d120bcSMark JohnstonIt is also possible, though rather uncommon, for a
56738d120bcSMark Johnston.Nm
568ef36b3f7SMark Johnstonfile to have multiple labels.
569ef36b3f7SMark JohnstonLabels are placed one after another, every eight bytes.
570ef36b3f7SMark 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
574ef36b3f7SMark Johnstonin the symbol table to a type identifier.
575ef36b3f7SMark 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
586ef36b3f7SMark Johnstondata.
587ef36b3f7SMark JohnstonNot every object is included in this section.
588*7421ff07SMark JohnstonSpecifically, when walking the symbol table, an entry is skipped if it matches
589*7421ff07SMark Johnstonany 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*7421ff07SMark Johnstonreturn value.
661ef36b3f7SMark JohnstonSimilar to
66238d120bcSMark Johnston.Sx The Object Section ,
66338d120bcSMark Johnstonthe function section encodes information for all symbols of type
66438d120bcSMark Johnston.Sy STT_FUNCTION ,
665ef36b3f7SMark Johnstonexcepting those that fit specific criteria.
666ef36b3f7SMark JohnstonUnlike with objects, because functions have a variable number of arguments, they
667ef36b3f7SMark 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) .
673ef36b3f7SMark JohnstonFunctions with arguments are encoded differently.
674ef36b3f7SMark JohnstonHere, the variable length is turned into the number of arguments in the
675ef36b3f7SMark Johnstonfunction.
676ef36b3f7SMark JohnstonIf a function is a
67738d120bcSMark Johnston.Sy varargs
678ef36b3f7SMark Johnstontype function, then the number of arguments is increased by one.
679ef36b3f7SMark 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
683ef36b3f7SMark Johnstonnext function is encoded.
684ef36b3f7SMark JohnstonFor functions with type information, the next
68538d120bcSMark Johnston.Sy uint16_t
686ef36b3f7SMark Johnstonis encoded with the type identifier of the return type of the function.
687ef36b3f7SMark JohnstonIt is followed by each of the type identifiers of the arguments, if any exist,
688ef36b3f7SMark Johnstonin the order that they appear in the function.
689ef36b3f7SMark JohnstonTherefore, argument 0 is the first type identifier and so on.
690ef36b3f7SMark JohnstonWhen a function has a final varargs argument, that is encoded with the type
691ef36b3f7SMark Johnstonidentifier of zero.
69238d120bcSMark Johnston.Lp
69338d120bcSMark JohnstonLike
69438d120bcSMark Johnston.Sx The Object Section ,
695ef36b3f7SMark Johnstonthe function section is encoded in the order of the symbol table.
696ef36b3f7SMark JohnstonIt has similar, but slightly different considerations from objects.
697ef36b3f7SMark JohnstonWhile iterating the symbol table, if any of the following conditions are true,
698ef36b3f7SMark 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
720ef36b3f7SMark Johnstondata.
721ef36b3f7SMark JohnstonIt encodes all of the information about the types themselves.
722ef36b3f7SMark JohnstonThe base of the type information comes in two forms, a short form and a long
723ef36b3f7SMark Johnstonform, each of which may be followed by a variable number of arguments.
724ef36b3f7SMark 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
758ef36b3f7SMark Johnstonto store the number of bytes.
759ef36b3f7SMark JohnstonIf the number of bytes in a structure would exceed 0xfffe, then the alternate
760ef36b3f7SMark Johnstonform, the
76138d120bcSMark Johnston.Sy ctf_type_t ,
762ef36b3f7SMark Johnstonis used instead.
763ef36b3f7SMark 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
767ef36b3f7SMark Johnston(0xffff).
768ef36b3f7SMark 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
780ef36b3f7SMark Johnstonstructure.
781ef36b3f7SMark JohnstonThe individual sections for each kind have more information.
78238d120bcSMark Johnston.Lp
783ef36b3f7SMark JohnstonTypes are written out in order.
784ef36b3f7SMark JohnstonTherefore the first entry encountered has a type id of 0x1, or 0x8000 if a
785ef36b3f7SMark Johnstonchild.
786ef36b3f7SMark JohnstonThe member
78738d120bcSMark Johnston.Em ctt_name
78838d120bcSMark Johnstonis encoded as described in the section
78938d120bcSMark Johnston.Sx String Identifiers .
790ef36b3f7SMark JohnstonThe string that it points to is the name of the type.
791ef36b3f7SMark JohnstonIf the identifier points to an empty string (one that consists solely of a null
792ef36b3f7SMark Johnstonterminator) then the type does not have a name, this is common with anonymous
793*7421ff07SMark Johnstonstructures and unions that only have a typedef to name them, as well as
794ef36b3f7SMark 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 .
800*7421ff07SMark JohnstonThe type's kind tells us how to interpret the remaining data in the
80138d120bcSMark Johnston.Sy ctf_type_t
802ef36b3f7SMark Johnstonand any variable length data that may exist.
803ef36b3f7SMark JohnstonThe rest of this section will be broken down into the interpretation of the
804ef36b3f7SMark Johnstonvarious kinds.
80538d120bcSMark Johnston.Ss Encoding of Integers
80638d120bcSMark JohnstonIntegers, which are of type
80738d120bcSMark Johnston.Sy CTF_K_INTEGER ,
808ef36b3f7SMark Johnstonhave no variable length arguments.
809ef36b3f7SMark JohnstonInstead, they are followed by a four byte
81038d120bcSMark Johnston.Sy uint_t
811ef36b3f7SMark Johnstonwhich describes their encoding.
812ef36b3f7SMark JohnstonAll integers must be encoded with a variable length of zero.
813ef36b3f7SMark JohnstonThe
81438d120bcSMark Johnston.Em ctt_size
815ef36b3f7SMark Johnstonmember describes the length of the integer in bytes.
816ef36b3f7SMark 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
852ef36b3f7SMark Johnstonflag set.
853ef36b3f7SMark 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
860ef36b3f7SMark Johnstonflag set.
861ef36b3f7SMark JohnstonIf the flag
86238d120bcSMark Johnston.Sy CTF_INT_BOOL
863ef36b3f7SMark Johnstonis set, that indicates that the integer represents a boolean type.
864ef36b3f7SMark JohnstonFor example, the intrinsic C type
86538d120bcSMark Johnston.Sy _Bool
86638d120bcSMark Johnstonwould have the
86738d120bcSMark Johnston.Sy CTF_INT_BOOL
868ef36b3f7SMark Johnstonflag set.
869ef36b3f7SMark 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 ,
876ef36b3f7SMark Johnstonare similar to their integer counterparts.
877ef36b3f7SMark JohnstonThey have no variable length arguments and are followed by a four byte encoding
878ef36b3f7SMark Johnstonwhich describes the kind of float that exists.
879ef36b3f7SMark JohnstonThe
88038d120bcSMark Johnston.Em ctt_size
881ef36b3f7SMark Johnstonmember is the size, in bytes, of the float.
882ef36b3f7SMark 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
907*7421ff07SMark JohnstonWhere as the encoding for integers is a series of flags, the encoding for
908ef36b3f7SMark Johnstonfloats maps to a specific kind of float.
909ef36b3f7SMark JohnstonIt is not a flag-based value.
910ef36b3f7SMark JohnstonThe kinds of floats correspond to both their size, and the encoding.
911ef36b3f7SMark JohnstonThis covers all of the basic C intrinsic floating point types.
912ef36b3f7SMark 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 ,
930ef36b3f7SMark Johnstonhave no variable length arguments.
931ef36b3f7SMark JohnstonThey are followed by a structure which describes the number of elements in the
932ef36b3f7SMark Johnstonarray, the type identifier of the elements in the array, and the type identifier
933ef36b3f7SMark Johnstonof the index of the array.
934ef36b3f7SMark JohnstonWith arrays, the
93538d120bcSMark Johnston.Em ctt_size
936ef36b3f7SMark Johnstonmember is set to zero.
937ef36b3f7SMark 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
956ef36b3f7SMark Johnstonis a simple four byte unsigned count of the number of elements.
957ef36b3f7SMark 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 ,
961ef36b3f7SMark Johnstonuse the variable length list to be the number of arguments in the function.
962ef36b3f7SMark JohnstonWhen the function has a final member which is a varargs, then the argument count
963ef36b3f7SMark Johnstonis incremented by one to account for the variable argument.
964ef36b3f7SMark 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
972ef36b3f7SMark Johnstonthe function, if any.
973ef36b3f7SMark JohnstonEach one is represented by a
97438d120bcSMark Johnston.Sy uint16_t
97538d120bcSMark Johnstonand encoded according to the
97638d120bcSMark Johnston.Sx Type Identifiers
977ef36b3f7SMark Johnstonsection.
978ef36b3f7SMark JohnstonIf the function's last argument is of type varargs, then it is also written out,
979ef36b3f7SMark Johnstonbut the type identifier is zero.
980ef36b3f7SMark JohnstonThis is included in the count of the function's arguments.
981*7421ff07SMark JohnstonAn extra type identifier may follow the argument and return type identifiers
982*7421ff07SMark Johnstonin order to maintain four-byte alignment for the following type definition.
983*7421ff07SMark JohnstonSuch a type identifier is not included in the argument count and has a value
984*7421ff07SMark Johnstonof zero.
98538d120bcSMark Johnston.Ss Encoding of Structures and Unions
98638d120bcSMark JohnstonStructures and Unions, which are encoded with
98738d120bcSMark Johnston.Sy CTF_K_STRUCT
98838d120bcSMark Johnstonand
98938d120bcSMark Johnston.Sy CTF_K_UNION
990ef36b3f7SMark Johnstonrespectively,  are very similar constructs in C.
991*7421ff07SMark JohnstonThe main difference between them is the fact that members of a structure
992*7421ff07SMark Johnstonfollow one another, where as in a union, all members share the same memory.
993ef36b3f7SMark JohnstonThey are also very similar in terms of their encoding in
99438d120bcSMark Johnston.Nm .
99538d120bcSMark JohnstonThe variable length argument for structures and unions represents the number of
996ef36b3f7SMark Johnstonmembers that they have.
997ef36b3f7SMark JohnstonThe value of the member
99838d120bcSMark Johnston.Em ctt_size
999ef36b3f7SMark Johnstonis the size of the structure and union.
1000ef36b3f7SMark JohnstonThere are two different structures which are used to encode members in the
1001ef36b3f7SMark Johnstonvariable list.
1002ef36b3f7SMark JohnstonWhen the size of a structure or union is greater than or equal to the large
1003ef36b3f7SMark Johnstonmember threshold, 8192, then a different structure is used to encode the member,
1004ef36b3f7SMark Johnstonall members are encoded using the same structure.
1005ef36b3f7SMark JohnstonThe structure for members is as follows:
100638d120bcSMark Johnston.Bd -literal
100738d120bcSMark Johnstontypedef struct ctf_member {
100838d120bcSMark Johnston	uint_t ctm_name;	/* reference to name in string table */
100938d120bcSMark Johnston	ushort_t ctm_type;	/* reference to type of member */
101038d120bcSMark Johnston	ushort_t ctm_offset;	/* offset of this member in bits */
101138d120bcSMark Johnston} ctf_member_t;
101238d120bcSMark Johnston
101338d120bcSMark Johnstontypedef struct ctf_lmember {
101438d120bcSMark Johnston	uint_t ctlm_name;	/* reference to name in string table */
101538d120bcSMark Johnston	ushort_t ctlm_type;	/* reference to type of member */
101638d120bcSMark Johnston	ushort_t ctlm_pad;	/* padding */
101738d120bcSMark Johnston	uint_t ctlm_offsethi;	/* high 32 bits of member offset in bits */
101838d120bcSMark Johnston	uint_t ctlm_offsetlo;	/* low 32 bits of member offset in bits */
101938d120bcSMark Johnston} ctf_lmember_t;
102038d120bcSMark Johnston.Ed
102138d120bcSMark Johnston.Lp
102238d120bcSMark JohnstonBoth the
102338d120bcSMark Johnston.Em ctm_name
102438d120bcSMark Johnstonand
102538d120bcSMark Johnston.Em ctlm_name
1026ef36b3f7SMark Johnstonrefer to the name of the member.
1027ef36b3f7SMark JohnstonThe name is encoded as an offset into the string table as described by the
1028ef36b3f7SMark Johnstonsection
102938d120bcSMark Johnston.Sx String Identifiers .
103038d120bcSMark JohnstonThe members
103138d120bcSMark Johnston.Sy ctm_type
103238d120bcSMark Johnstonand
103338d120bcSMark Johnston.Sy ctlm_type
1034ef36b3f7SMark Johnstonboth refer to the type of the member.
1035ef36b3f7SMark JohnstonThey are encoded as per the section
103638d120bcSMark Johnston.Sx Type Identifiers .
103738d120bcSMark Johnston.Lp
103838d120bcSMark JohnstonThe last piece of information that is present is the offset which describes the
1039*7421ff07SMark Johnstonoffset in memory at which the member begins.
1040*7421ff07SMark JohnstonFor unions, this value will always be zero because each member of a union has
1041*7421ff07SMark Johnstonan offset of zero.
1042ef36b3f7SMark JohnstonFor structures, this is the offset in
104338d120bcSMark Johnston.Sy bits
1044*7421ff07SMark Johnstonat which the member begins.
1045ef36b3f7SMark JohnstonNote that a compiler may lay out a type with padding.
104638d120bcSMark JohnstonThis means that the difference in offset between two consecutive members may be
1047ef36b3f7SMark Johnstonlarger than the size of the member.
1048ef36b3f7SMark JohnstonWhen the size of the overall structure is strictly less than 8192 bytes, the
1049ef36b3f7SMark Johnstonnormal structure,
105038d120bcSMark Johnston.Sy ctf_member_t ,
105138d120bcSMark Johnstonis used and the offset in bits is stored in the member
105238d120bcSMark Johnston.Em ctm_offset .
105338d120bcSMark JohnstonHowever, when the size of the structure is greater than or equal to 8192 bytes,
1054ef36b3f7SMark Johnstonthen the number of bits is split into two 32-bit quantities.
1055ef36b3f7SMark JohnstonOne member,
105638d120bcSMark Johnston.Em ctlm_offsethi ,
105738d120bcSMark Johnstonrepresents the upper 32 bits of the offset, while the other member,
105838d120bcSMark Johnston.Em ctlm_offsetlo ,
1059ef36b3f7SMark Johnstonrepresents the lower 32 bits of the offset.
1060ef36b3f7SMark JohnstonThese can be joined together to get a 64-bit sized offset in bits by shifting
1061ef36b3f7SMark Johnstonthe member
106238d120bcSMark Johnston.Em ctlm_offsethi
106338d120bcSMark Johnstonto the left by thirty two and then doing a binary or of
106438d120bcSMark Johnston.Em ctlm_offsetlo .
106538d120bcSMark Johnston.Ss Encoding of Enumerations
106638d120bcSMark JohnstonEnumerations, noted by the type
106738d120bcSMark Johnston.Sy CTF_K_ENUM ,
1068ef36b3f7SMark Johnstonare similar to structures.
1069ef36b3f7SMark JohnstonEnumerations use the variable list to note the number of values that the
1070ef36b3f7SMark Johnstonenumeration contains, which we'll term enumerators.
1071ef36b3f7SMark JohnstonIn C, an enumeration is always equivalent to the intrinsic type
107238d120bcSMark Johnston.Sy int ,
107338d120bcSMark Johnstonthus the value of the member
107438d120bcSMark Johnston.Em ctt_size
107538d120bcSMark Johnstonis always the size of an integer which is determined based on the current model.
1076*7421ff07SMark JohnstonFor
1077*7421ff07SMark Johnston.Fx
1078*7421ff07SMark Johnstonsystems, this will always be 4, as an integer is always defined to
107938d120bcSMark Johnstonbe 4 bytes large in both
108038d120bcSMark Johnston.Sy ILP32
108138d120bcSMark Johnstonand
108238d120bcSMark Johnston.Sy LP64 ,
108338d120bcSMark Johnstonregardless of the architecture.
1084*7421ff07SMark JohnstonFor further details, see
1085*7421ff07SMark Johnston.Xr arch 7 .
108638d120bcSMark Johnston.Lp
108738d120bcSMark JohnstonThe enumerators encoded in an enumeration have the following structure in the
108838d120bcSMark Johnstonvariable list:
108938d120bcSMark Johnston.Bd -literal
109038d120bcSMark Johnstontypedef struct ctf_enum {
109138d120bcSMark Johnston	uint_t cte_name;	/* reference to name in string table */
109238d120bcSMark Johnston	int cte_value;		/* value associated with this name */
109338d120bcSMark Johnston} ctf_enum_t;
109438d120bcSMark Johnston.Ed
109538d120bcSMark Johnston.Pp
109638d120bcSMark JohnstonThe member
109738d120bcSMark Johnston.Em cte_name
109838d120bcSMark Johnstonrefers to the name of the enumerator's value, it is encoded according to the
109938d120bcSMark Johnstonrules in the section
110038d120bcSMark Johnston.Sx String Identifiers .
110138d120bcSMark JohnstonThe member
110238d120bcSMark Johnston.Em cte_value
110338d120bcSMark Johnstoncontains the integer value of this enumerator.
110438d120bcSMark Johnston.Ss Encoding of Forward References
110538d120bcSMark JohnstonForward references, types of kind
110638d120bcSMark Johnston.Sy CTF_K_FORWARD ,
110738d120bcSMark Johnstonin a
110838d120bcSMark Johnston.Nm
1109ef36b3f7SMark Johnstonfile refer to types which may not have a definition at all, only a name.
1110ef36b3f7SMark JohnstonIf the
111138d120bcSMark Johnston.Nm
111238d120bcSMark Johnstonfile is a child, then it may be that the forward is resolved to an
111338d120bcSMark Johnstonactual type in the parent, otherwise the definition may be in another
111438d120bcSMark Johnston.Nm
1115ef36b3f7SMark Johnstoncontainer or may not be known at all.
1116ef36b3f7SMark JohnstonThe only member of the
111738d120bcSMark Johnston.Sy ctf_type_t
111838d120bcSMark Johnstonthat matters for a forward declaration is the
111938d120bcSMark Johnston.Em ctt_name
112038d120bcSMark Johnstonwhich points to the name of the forward reference in the string table as
1121ef36b3f7SMark Johnstondescribed earlier.
1122ef36b3f7SMark JohnstonThere is no other information recorded for forward references.
112338d120bcSMark Johnston.Ss Encoding of Pointers, Typedefs, Volatile, Const, and Restrict
112438d120bcSMark JohnstonPointers, typedefs, volatile, const, and restrict are all similar in
112538d120bcSMark Johnston.Nm .
1126ef36b3f7SMark JohnstonThey all refer to another type.
1127ef36b3f7SMark JohnstonIn the case of typedefs, they provide an alternate name, while volatile, const,
1128ef36b3f7SMark Johnstonand restrict change how the type is interpreted in the C programming language.
1129ef36b3f7SMark JohnstonThis covers the
113038d120bcSMark Johnston.Nm
113138d120bcSMark Johnstonkinds
113238d120bcSMark Johnston.Sy CTF_K_POINTER ,
113338d120bcSMark Johnston.Sy CTF_K_TYPEDEF ,
113438d120bcSMark Johnston.Sy CTF_K_VOLATILE ,
113538d120bcSMark Johnston.Sy CTF_K_RESTRICT ,
113638d120bcSMark Johnstonand
113738d120bcSMark Johnston.Sy CTF_K_CONST .
113838d120bcSMark Johnston.Lp
113938d120bcSMark JohnstonThese types have no variable list entries and use the member
114038d120bcSMark Johnston.Em ctt_type
114138d120bcSMark Johnstonto refer to the base type that they modify.
114238d120bcSMark Johnston.Ss Encoding of Unknown Types
114338d120bcSMark JohnstonTypes with the kind
114438d120bcSMark Johnston.Sy CTF_K_UNKNOWN
1145ef36b3f7SMark Johnstonare used to indicate gaps in the type identifier space.
1146ef36b3f7SMark JohnstonThese entries consume an identifier, but do not define anything.
1147ef36b3f7SMark JohnstonNothing should refer to these gap identifiers.
114838d120bcSMark Johnston.Ss Dependencies Between Types
1149ef36b3f7SMark JohnstonC types can be imagined as a directed, cyclic, graph.
1150ef36b3f7SMark JohnstonStructures and unions may refer to each other in a way that creates a cyclic
1151ef36b3f7SMark Johnstondependency.
1152ef36b3f7SMark JohnstonIn cases such as these, the entire type section must be read in and processed.
1153ef36b3f7SMark JohnstonConsumers must not assume that every type can be laid out in dependency order;
1154ef36b3f7SMark Johnstonthey cannot.
115538d120bcSMark Johnston.Ss The String Section
115638d120bcSMark JohnstonThe last section of the
115738d120bcSMark Johnston.Nm
115838d120bcSMark Johnstonfile is the
115938d120bcSMark Johnston.Sy string
1160ef36b3f7SMark Johnstonsection.
1161ef36b3f7SMark JohnstonThis section encodes all of the strings that appear throughout the other
1162ef36b3f7SMark Johnstonsections.
1163ef36b3f7SMark JohnstonIt is laid out as a series of characters followed by a null terminator.
1164ef36b3f7SMark JohnstonGenerally, all names are written out in ASCII, as most C compilers do not allow
1165*7421ff07SMark Johnstonany characters to appear in identifiers outside of a subset of ASCII.
1166ef36b3f7SMark JohnstonHowever, any extended characters sets should be written out as a series of UTF-8
1167ef36b3f7SMark Johnstonbytes.
116838d120bcSMark Johnston.Lp
116938d120bcSMark JohnstonThe first entry in the section, at offset zero, is a single null
1170ef36b3f7SMark Johnstonterminator to reference the empty string.
1171ef36b3f7SMark JohnstonFollowing that, each C string should be written out, including the null
1172ef36b3f7SMark Johnstonterminator.
1173ef36b3f7SMark JohnstonOffsets that refer to something in this section should refer to the first byte
1174ef36b3f7SMark Johnstonwhich begins a string.
1175ef36b3f7SMark JohnstonBeyond the first byte in the section being the null terminator, the order of
1176ef36b3f7SMark Johnstonstrings is unimportant.
1177*7421ff07SMark Johnston.Ss Data Encoding and ELF Considerations
117838d120bcSMark Johnston.Nm
117938d120bcSMark Johnstondata is generally included in ELF objects which specify information to
1180ef36b3f7SMark Johnstonidentify the architecture and endianness of the file.
1181ef36b3f7SMark JohnstonA
118238d120bcSMark Johnston.Nm
1183ef36b3f7SMark Johnstoncontainer inside such an object must match the endianness of the ELF object.
1184ef36b3f7SMark JohnstonAside from the question of the endian encoding of data, there should be no other
1185ef36b3f7SMark Johnstondifferences between architectures.
1186ef36b3f7SMark JohnstonWhile many of the types in this document refer to non-fixed size C integral
1187ef36b3f7SMark Johnstontypes, they are equivalent in the models
118838d120bcSMark Johnston.Sy ILP32
118938d120bcSMark Johnstonand
119038d120bcSMark Johnston.Sy LP64 .
119138d120bcSMark JohnstonIf any other model is being used with
119238d120bcSMark Johnston.Nm
119338d120bcSMark Johnstondata that has different sizes, then it must not use the model's sizes for
119438d120bcSMark Johnstonthose integral types and instead use the fixed size equivalents based on an
119538d120bcSMark Johnston.Sy ILP32
119638d120bcSMark Johnstonenvironment.
119738d120bcSMark Johnston.Lp
119838d120bcSMark JohnstonWhen placing a
119938d120bcSMark Johnston.Nm
120038d120bcSMark Johnstoncontainer inside of an ELF object, there are certain conventions that are
120138d120bcSMark Johnstonexpected for the purposes of tooling being able to find the
120238d120bcSMark Johnston.Nm
1203ef36b3f7SMark Johnstondata.
1204ef36b3f7SMark JohnstonIn particular, a given ELF object should only contain a single
120538d120bcSMark Johnston.Nm
1206ef36b3f7SMark Johnstonsection.
1207ef36b3f7SMark JohnstonMultiple containers should be merged together into a single one.
120838d120bcSMark Johnston.Lp
120938d120bcSMark JohnstonThe
121038d120bcSMark Johnston.Nm
1211ef36b3f7SMark Johnstonfile should be included in its own ELF section.
1212ef36b3f7SMark JohnstonThe section's name must be
121338d120bcSMark Johnston.Ql .SUNW_ctf .
121438d120bcSMark JohnstonThe type of the section must be
121538d120bcSMark Johnston.Sy SHT_PROGBITS .
121638d120bcSMark JohnstonThe section should have a link set to the symbol table and its address
121738d120bcSMark Johnstonalignment must be 4.
121838d120bcSMark Johnston.Sh SEE ALSO
121938d120bcSMark Johnston.Xr dtrace 1 ,
122038d120bcSMark Johnston.Xr elf 3 ,
122138d120bcSMark Johnston.Xr gelf 3 ,
122238d120bcSMark Johnston.Xr a.out 5 ,
1223*7421ff07SMark Johnston.Xr elf 5 ,
1224*7421ff07SMark Johnston.Xr arch 7
1225