Next: , Previous: , Up: The type section   [Contents][Index]


2.3.2 Type indexes and type IDs

Types are referred to within the CTF file via type IDs. A type ID is a number from 0 to 2^32, from a space divided in half. Types 2^31-1 and below are in the parent range: these IDs are used for dictionaries that have not had any other dictionary ctf_imported into it as a parent. Both completely standalone dictionaries and parent dictionaries with children hanging off them have types in this range. Types 2^31 and above are in the child range: only types in child dictionaries are in this range.

These IDs appear in ctf_type_t.ctt_type (see section The type section), but the types themselves have no visible ID: quite intentionally, because adding an ID uses space, and every ID is different so they don’t compress well. The IDs are implicit: at open time, the consumer walks through the entire type section and counts the types in the type section. The type section is an array of variable-length elements, so each entry could be considered as having an index, starting from 1. We count these indexes and associate each with its corresponding ctf_type_t or ctf_stype_t.

Lookups of types with IDs in the parent space look in the parent dictionary if this dictionary has one associated with it; lookups of types with IDs in the child space error out if the dictionary does not have a parent, and otherwise convert the ID into an index by shaving off the top bit and look up the index in the child.

These properties mean that the same dictionary can be used as a parent of child dictionaries and can also be used directly with no children at all, but a dictionary created as a child dictionary must always be associated with a parent — usually, the same parent — because its references to its own types have the high bit turned on and this is only flipped off again if this is a child dictionary. (This is not a problem, because if you don’t associate the child with a parent, any references within it to its parent types will fail, and there are almost certain to be many such references, or why is it a child at all?)

This does mean that consumers should keep a close eye on the distinction between type IDs and type indexes: if you mix them up, everything will appear to work as long as you’re only using parent dictionaries or standalone dictionaries, but as soon as you start using children, everything will fail horribly.

Type index zero, and type ID zero, are used to indicate that this type cannot be represented in CTF as currently constituted: they are emitted by the compiler, but all type chains that terminate in the unknown type are erased at link time (structure fields that use them just vanish, etc). So you will probably never see a use of type zero outside the symtypetab sections, where they serve as sentinels of sorts, to indicate symbols with no associated type.

The macros CTF_V2_TYPE_TO_INDEX and CTF_V2_INDEX_TO_TYPE may help in translation between types and indexes: CTF_V2_TYPE_ISPARENT and CTF_V2_TYPE_ISCHILD can be used to tell whether a given ID is in the parent or child range.

It is quite possible and indeed common for type IDs to point forward in the dictionary, as well as backward.


Next: , Previous: , Up: The type section   [Contents][Index]