1 1.1 christos /* Implementation header. 2 1.1.1.5 christos Copyright (C) 2019-2026 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of libctf. 5 1.1 christos 6 1.1 christos libctf is free software; you can redistribute it and/or modify it under 7 1.1 christos the terms of the GNU General Public License as published by the Free 8 1.1 christos Software Foundation; either version 3, or (at your option) any later 9 1.1 christos version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, but 12 1.1 christos WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 1.1 christos See the GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program; see the file COPYING. If not see 18 1.1 christos <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1 christos #ifndef _CTF_IMPL_H 21 1.1 christos #define _CTF_IMPL_H 22 1.1 christos 23 1.1 christos #include "config.h" 24 1.1 christos #include <errno.h> 25 1.1 christos #include "ctf-decls.h" 26 1.1 christos #include <ctf-api.h> 27 1.1.1.2 christos #include "ctf-sha1.h" 28 1.1 christos #include <sys/types.h> 29 1.1 christos #include <stdlib.h> 30 1.1 christos #include <stdarg.h> 31 1.1.1.2 christos #include <stddef.h> 32 1.1 christos #include <stdio.h> 33 1.1 christos #include <stdint.h> 34 1.1.1.2 christos #include <string.h> 35 1.1 christos #include <limits.h> 36 1.1 christos #include <ctype.h> 37 1.1 christos #include <elf.h> 38 1.1 christos #include <bfd.h> 39 1.1.1.2 christos #include "hashtab.h" 40 1.1.1.2 christos #include "ctf-intl.h" 41 1.1 christos 42 1.1 christos #ifdef __cplusplus 43 1.1 christos extern "C" 44 1.1.1.2 christos { 45 1.1 christos #endif 46 1.1 christos 47 1.1.1.2 christos /* Tuning. */ 48 1.1.1.2 christos 49 1.1.1.2 christos /* The proportion of symtypetab entries which must be pads before we consider it 50 1.1.1.2 christos worthwhile to emit a symtypetab section as an index. Indexes cost time to 51 1.1.1.2 christos look up, but save space all told. Do not set to 1, since this will cause 52 1.1.1.2 christos indexes to be eschewed completely, even in child dicts, at considerable space 53 1.1.1.2 christos cost. */ 54 1.1.1.2 christos #define CTF_INDEX_PAD_THRESHOLD .75 55 1.1.1.2 christos 56 1.1 christos /* Compiler attributes. */ 57 1.1 christos 58 1.1 christos #if defined (__GNUC__) 59 1.1 christos 60 1.1 christos /* GCC. We assume that all compilers claiming to be GCC support sufficiently 61 1.1 christos many GCC attributes that the code below works. If some non-GCC compilers 62 1.1 christos masquerading as GCC in fact do not implement these attributes, version checks 63 1.1 christos may be required. */ 64 1.1 christos 65 1.1 christos /* We use the _libctf_*_ pattern to avoid clashes with any future attribute 66 1.1 christos macros glibc may introduce, which have names of the pattern 67 1.1 christos __attribute_blah__. */ 68 1.1 christos 69 1.1.1.4 christos #if defined (__clang__) 70 1.1 christos #define _libctf_printflike_(string_index,first_to_check) \ 71 1.1 christos __attribute__ ((__format__ (__printf__, (string_index), (first_to_check)))) 72 1.1.1.4 christos #else 73 1.1.1.4 christos #define _libctf_printflike_(string_index,first_to_check) \ 74 1.1.1.4 christos __attribute__ ((__format__ (__gnu_printf__, (string_index), (first_to_check)))) 75 1.1.1.4 christos #endif 76 1.1 christos #define _libctf_unlikely_(x) __builtin_expect ((x), 0) 77 1.1 christos #define _libctf_unused_ __attribute__ ((__unused__)) 78 1.1 christos #define _libctf_malloc_ __attribute__((__malloc__)) 79 1.1.1.2 christos #define _libctf_nonnull_(params) __attribute__((__nonnull__ params)) 80 1.1.1.2 christos 81 1.1.1.2 christos #else 82 1.1.1.2 christos 83 1.1.1.2 christos #define _libctf_printflike_(string_index,first_to_check) 84 1.1.1.2 christos #define _libctf_unlikely_(x) (x) 85 1.1.1.2 christos #define _libctf_unused_ 86 1.1.1.2 christos #define _libctf_malloc_ 87 1.1.1.2 christos #define _libctf_nonnull_(params) 88 1.1.1.2 christos #define __extension__ 89 1.1.1.2 christos 90 1.1.1.2 christos #endif 91 1.1 christos 92 1.1.1.2 christos #if defined (ENABLE_LIBCTF_HASH_DEBUGGING) && !defined (NDEBUG) 93 1.1.1.2 christos #include <assert.h> 94 1.1.1.2 christos #define ctf_assert(fp, expr) (assert (expr), 1) 95 1.1.1.2 christos #else 96 1.1.1.2 christos #define ctf_assert(fp, expr) \ 97 1.1.1.2 christos _libctf_unlikely_ (ctf_assert_internal (fp, __FILE__, __LINE__, \ 98 1.1.1.2 christos #expr, !!(expr))) 99 1.1 christos #endif 100 1.1 christos 101 1.1 christos /* libctf in-memory state. */ 102 1.1 christos 103 1.1 christos typedef struct ctf_fixed_hash ctf_hash_t; /* Private to ctf-hash.c. */ 104 1.1 christos typedef struct ctf_dynhash ctf_dynhash_t; /* Private to ctf-hash.c. */ 105 1.1.1.2 christos typedef struct ctf_dynset ctf_dynset_t; /* Private to ctf-hash.c. */ 106 1.1 christos 107 1.1 christos typedef struct ctf_strs 108 1.1 christos { 109 1.1 christos const char *cts_strs; /* Base address of string table. */ 110 1.1 christos size_t cts_len; /* Size of string table in bytes. */ 111 1.1 christos } ctf_strs_t; 112 1.1 christos 113 1.1 christos typedef struct ctf_strs_writable 114 1.1 christos { 115 1.1 christos char *cts_strs; /* Base address of string table. */ 116 1.1 christos size_t cts_len; /* Size of string table in bytes. */ 117 1.1 christos } ctf_strs_writable_t; 118 1.1 christos 119 1.1 christos typedef struct ctf_dmodel 120 1.1 christos { 121 1.1 christos const char *ctd_name; /* Data model name. */ 122 1.1 christos int ctd_code; /* Data model code. */ 123 1.1 christos size_t ctd_pointer; /* Size of void * in bytes. */ 124 1.1 christos size_t ctd_char; /* Size of char in bytes. */ 125 1.1 christos size_t ctd_short; /* Size of short in bytes. */ 126 1.1 christos size_t ctd_int; /* Size of int in bytes. */ 127 1.1 christos size_t ctd_long; /* Size of long in bytes. */ 128 1.1 christos } ctf_dmodel_t; 129 1.1 christos 130 1.1 christos typedef struct ctf_lookup 131 1.1 christos { 132 1.1 christos const char *ctl_prefix; /* String prefix for this lookup. */ 133 1.1 christos size_t ctl_len; /* Length of prefix string in bytes. */ 134 1.1.1.4 christos ctf_dynhash_t *ctl_hash; /* Pointer to hash table for lookup. */ 135 1.1 christos } ctf_lookup_t; 136 1.1 christos 137 1.1.1.2 christos typedef struct ctf_dictops 138 1.1 christos { 139 1.1 christos uint32_t (*ctfo_get_kind) (uint32_t); 140 1.1 christos uint32_t (*ctfo_get_root) (uint32_t); 141 1.1 christos uint32_t (*ctfo_get_vlen) (uint32_t); 142 1.1.1.2 christos ssize_t (*ctfo_get_ctt_size) (const ctf_dict_t *, const ctf_type_t *, 143 1.1 christos ssize_t *, ssize_t *); 144 1.1.1.2 christos ssize_t (*ctfo_get_vbytes) (ctf_dict_t *, unsigned short, ssize_t, size_t); 145 1.1.1.2 christos } ctf_dictops_t; 146 1.1 christos 147 1.1 christos typedef struct ctf_list 148 1.1 christos { 149 1.1 christos struct ctf_list *l_prev; /* Previous pointer or tail pointer. */ 150 1.1 christos struct ctf_list *l_next; /* Next pointer or head pointer. */ 151 1.1 christos } ctf_list_t; 152 1.1 christos 153 1.1 christos typedef enum 154 1.1 christos { 155 1.1 christos CTF_PREC_BASE, 156 1.1 christos CTF_PREC_POINTER, 157 1.1 christos CTF_PREC_ARRAY, 158 1.1 christos CTF_PREC_FUNCTION, 159 1.1 christos CTF_PREC_MAX 160 1.1 christos } ctf_decl_prec_t; 161 1.1 christos 162 1.1 christos typedef struct ctf_decl_node 163 1.1 christos { 164 1.1 christos ctf_list_t cd_list; /* Linked list pointers. */ 165 1.1 christos ctf_id_t cd_type; /* Type identifier. */ 166 1.1 christos uint32_t cd_kind; /* Type kind. */ 167 1.1 christos uint32_t cd_n; /* Type dimension if array. */ 168 1.1 christos } ctf_decl_node_t; 169 1.1 christos 170 1.1 christos typedef struct ctf_decl 171 1.1 christos { 172 1.1 christos ctf_list_t cd_nodes[CTF_PREC_MAX]; /* Declaration node stacks. */ 173 1.1 christos int cd_order[CTF_PREC_MAX]; /* Storage order of decls. */ 174 1.1 christos ctf_decl_prec_t cd_qualp; /* Qualifier precision. */ 175 1.1 christos ctf_decl_prec_t cd_ordp; /* Ordered precision. */ 176 1.1 christos char *cd_buf; /* Buffer for output. */ 177 1.1 christos int cd_err; /* Saved error value. */ 178 1.1 christos int cd_enomem; /* Nonzero if OOM during printing. */ 179 1.1 christos } ctf_decl_t; 180 1.1 christos 181 1.1 christos typedef struct ctf_dtdef 182 1.1 christos { 183 1.1 christos ctf_list_t dtd_list; /* List forward/back pointers. */ 184 1.1 christos ctf_id_t dtd_type; /* Type identifier for this definition. */ 185 1.1 christos ctf_type_t dtd_data; /* Type node, including name. */ 186 1.1.1.2 christos size_t dtd_vlen_alloc; /* Total vlen space allocated. */ 187 1.1.1.2 christos unsigned char *dtd_vlen; /* Variable-length data for this type. */ 188 1.1 christos } ctf_dtdef_t; 189 1.1 christos 190 1.1 christos typedef struct ctf_dvdef 191 1.1 christos { 192 1.1 christos ctf_list_t dvd_list; /* List forward/back pointers. */ 193 1.1 christos char *dvd_name; /* Name associated with variable. */ 194 1.1 christos ctf_id_t dvd_type; /* Type of variable. */ 195 1.1 christos unsigned long dvd_snapshots; /* Snapshot count when inserted. */ 196 1.1 christos } ctf_dvdef_t; 197 1.1 christos 198 1.1.1.2 christos typedef struct ctf_err_warning 199 1.1 christos { 200 1.1.1.2 christos ctf_list_t cew_list; /* List forward/back pointers. */ 201 1.1.1.2 christos int cew_is_warning; /* 1 if warning, 0 if error. */ 202 1.1.1.2 christos char *cew_text; /* Error/warning text. */ 203 1.1.1.2 christos } ctf_err_warning_t; 204 1.1 christos 205 1.1 christos /* Atoms associate strings with a list of the CTF items that reference that 206 1.1.1.4 christos string, so that ctf_serialize() can instantiate all the strings using the 207 1.1 christos ctf_str_atoms and then reassociate them with the real string later. 208 1.1 christos 209 1.1 christos Strings can be interned into ctf_str_atom without having refs associated 210 1.1 christos with them, for values that are returned to callers, etc. Items are only 211 1.1.1.4 christos removed from this table on ctf_close(), but on every ctf_serialize(), all 212 1.1.1.4 christos the csa_refs in all entries are purged. */ 213 1.1.1.4 christos 214 1.1.1.4 christos #define CTF_STR_ATOM_FREEABLE 0x1 215 1.1 christos 216 1.1 christos typedef struct ctf_str_atom 217 1.1 christos { 218 1.1.1.4 christos char *csa_str; /* Pointer to string (also used as hash key). */ 219 1.1 christos ctf_list_t csa_refs; /* This string's refs. */ 220 1.1.1.4 christos ctf_list_t csa_movable_refs; /* This string's movable refs. */ 221 1.1.1.4 christos uint32_t csa_offset; /* Offset in this strtab, if any. */ 222 1.1 christos uint32_t csa_external_offset; /* External strtab offset, if any. */ 223 1.1 christos unsigned long csa_snapshot_id; /* Snapshot ID at time of creation. */ 224 1.1.1.4 christos int csa_flags; /* CTF_STR_ATOM_* flags. */ 225 1.1 christos } ctf_str_atom_t; 226 1.1 christos 227 1.1 christos /* The refs of a single string in the atoms table. */ 228 1.1 christos 229 1.1 christos typedef struct ctf_str_atom_ref 230 1.1 christos { 231 1.1 christos ctf_list_t caf_list; /* List forward/back pointers. */ 232 1.1 christos uint32_t *caf_ref; /* A single ref to this string. */ 233 1.1 christos } ctf_str_atom_ref_t; 234 1.1 christos 235 1.1.1.4 christos /* Like a ctf_str_atom_ref_t, but specific to movable refs. */ 236 1.1.1.4 christos 237 1.1.1.4 christos typedef struct ctf_str_atom_ref_movable 238 1.1.1.4 christos { 239 1.1.1.4 christos ctf_list_t caf_list; /* List forward/back pointers. */ 240 1.1.1.4 christos uint32_t *caf_ref; /* A single ref to this string. */ 241 1.1.1.4 christos ctf_dynhash_t *caf_movable_refs; /* Backpointer to ctf_str_movable_refs for this dict. */ 242 1.1.1.4 christos } ctf_str_atom_ref_movable_t; 243 1.1.1.4 christos 244 1.1.1.2 christos /* A single linker-provided symbol, during symbol addition, possibly before we 245 1.1.1.2 christos have been given external strtab refs. */ 246 1.1.1.2 christos typedef struct ctf_in_flight_dynsym 247 1.1.1.2 christos { 248 1.1.1.2 christos ctf_list_t cid_list; /* List forward/back pointers. */ 249 1.1.1.2 christos ctf_link_sym_t cid_sym; /* The linker-known symbol. */ 250 1.1.1.2 christos } ctf_in_flight_dynsym_t; 251 1.1.1.2 christos 252 1.1.1.2 christos /* The structure used as the key in a ctf_link_type_mapping. The value is a 253 1.1.1.2 christos type index, not a type ID. */ 254 1.1.1.2 christos 255 1.1.1.2 christos typedef struct ctf_link_type_key 256 1.1.1.2 christos { 257 1.1.1.2 christos ctf_dict_t *cltk_fp; 258 1.1.1.2 christos ctf_id_t cltk_idx; 259 1.1.1.2 christos } ctf_link_type_key_t; 260 1.1.1.2 christos 261 1.1.1.2 christos /* The structure used as the key in a cd_id_to_dict_t on 32-bit platforms. */ 262 1.1.1.2 christos typedef struct ctf_type_id_key 263 1.1.1.2 christos { 264 1.1.1.2 christos int ctii_input_num; 265 1.1.1.2 christos ctf_id_t ctii_type; 266 1.1.1.2 christos } ctf_type_id_key_t; 267 1.1.1.2 christos 268 1.1.1.2 christos /* Deduplicator state. 269 1.1.1.2 christos 270 1.1.1.2 christos The dedup state below uses three terms consistently. A "hash" is a 271 1.1.1.2 christos ctf_dynhash_t; a "hash value" is the hash value of a type as returned by 272 1.1.1.2 christos ctf_dedup_hash_type; a "global type ID" or "global ID" is a packed-together 273 1.1.1.2 christos reference to a single ctf_dict_t (by array index in an array of inputs) and 274 1.1.1.2 christos ctf_id_t, i.e. a single instance of some hash value in some input. 275 1.1.1.2 christos 276 1.1.1.2 christos The deduplication algorithm takes a bunch of inputs and yields a single 277 1.1.1.2 christos shared "output" and possibly many outputs corresponding to individual inputs 278 1.1.1.2 christos that still contain types after sharing of unconflicted types. Almost all 279 1.1.1.2 christos deduplicator state is stored in the struct ctf_dedup in the output, though a 280 1.1.1.2 christos (very) few things are stored in inputs for simplicity's sake, usually if they 281 1.1.1.2 christos are linking together things within the scope of a single TU. 282 1.1.1.2 christos 283 1.1.1.2 christos Flushed at the end of every ctf_dedup run. */ 284 1.1.1.2 christos 285 1.1.1.2 christos typedef struct ctf_dedup 286 1.1.1.2 christos { 287 1.1.1.2 christos /* The CTF linker flags in force for this dedup run. */ 288 1.1.1.2 christos int cd_link_flags; 289 1.1.1.2 christos 290 1.1.1.2 christos /* On 32-bit platforms only, a hash of global type IDs, in the form of 291 1.1.1.2 christos a ctf_link_type_id_key_t. */ 292 1.1.1.2 christos ctf_dynhash_t *cd_id_to_dict_t; 293 1.1.1.2 christos 294 1.1.1.2 christos /* Atoms tables of decorated names: maps undecorated name to decorated name. 295 1.1.1.2 christos (The actual allocations are in the CTF dict for the former and the real 296 1.1.1.2 christos atoms table for the latter). Uses the same namespaces as ctf_lookups, 297 1.1.1.2 christos below, but has no need for null-termination. */ 298 1.1.1.2 christos ctf_dynhash_t *cd_decorated_names[4]; 299 1.1.1.2 christos 300 1.1.1.2 christos /* Map type names to a hash from type hash value -> number of times each value 301 1.1.1.4 christos has appeared. Enumeration constants are tracked via the enum they appear 302 1.1.1.4 christos in. */ 303 1.1.1.2 christos ctf_dynhash_t *cd_name_counts; 304 1.1.1.2 christos 305 1.1.1.2 christos /* Map global type IDs to type hash values. Used to determine if types are 306 1.1.1.2 christos already hashed without having to recompute their hash values again, and to 307 1.1.1.2 christos link types together at later stages. Forwards that are peeked through to 308 1.1.1.2 christos structs and unions are not represented in here, so lookups that might be 309 1.1.1.2 christos such a type (in practice, all lookups) must go via cd_replaced_types first 310 1.1.1.2 christos to take this into account. Discarded before each rehashing. */ 311 1.1.1.2 christos ctf_dynhash_t *cd_type_hashes; 312 1.1.1.2 christos 313 1.1.1.2 christos /* Maps from the names of structs/unions/enums to a a single GID which is the 314 1.1.1.2 christos only appearance of that type in any input: if it appears in more than one 315 1.1.1.2 christos input, a value which is a GID with an input_num of -1 appears. Used in 316 1.1.1.2 christos share-duplicated link mode link modes to determine whether structs/unions 317 1.1.1.2 christos can be cited from multiple TUs. Only populated in that link mode. */ 318 1.1.1.2 christos ctf_dynhash_t *cd_struct_origin; 319 1.1.1.2 christos 320 1.1.1.2 christos /* Maps type hash values to a set of hash values of the types that cite them: 321 1.1.1.2 christos i.e., pointing backwards up the type graph. Used for recursive conflict 322 1.1.1.2 christos marking. Citations from tagged structures, unions, and forwards do not 323 1.1.1.2 christos appear in this graph. */ 324 1.1.1.2 christos ctf_dynhash_t *cd_citers; 325 1.1.1.2 christos 326 1.1.1.2 christos /* Maps type hash values to input global type IDs. The value is a set (a 327 1.1.1.2 christos hash) of global type IDs. Discarded before each rehashing. The result of 328 1.1.1.2 christos the ctf_dedup function. */ 329 1.1.1.2 christos ctf_dynhash_t *cd_output_mapping; 330 1.1.1.2 christos 331 1.1.1.2 christos /* A map giving the GID of the first appearance of each type for each type 332 1.1.1.2 christos hash value. */ 333 1.1.1.2 christos ctf_dynhash_t *cd_output_first_gid; 334 1.1.1.2 christos 335 1.1.1.2 christos /* Used to ensure that we never try to map a single type ID to more than one 336 1.1.1.2 christos hash. */ 337 1.1.1.2 christos ctf_dynhash_t *cd_output_mapping_guard; 338 1.1.1.2 christos 339 1.1.1.4 christos /* Maps from type hash values to an indication of their nonroot flag. 0 means 340 1.1.1.4 christos all root-visible; 1 means non-root-visible; 2 means a mixture. All values 341 1.1.1.4 christos other than 1 are deleted after hashing. */ 342 1.1.1.4 christos ctf_dynhash_t *cd_nonroot_consistency; 343 1.1.1.4 christos 344 1.1.1.2 christos /* Maps the global type IDs of structures in input TUs whose members still 345 1.1.1.2 christos need emission to the global type ID of the already-emitted target type 346 1.1.1.2 christos (which has no members yet) in the appropriate target. Uniquely, the latter 347 1.1.1.2 christos ID represents a *target* ID (i.e. the cd_output_mapping of some specified 348 1.1.1.2 christos input): we encode the shared (parent) dict with an ID of -1. */ 349 1.1.1.2 christos ctf_dynhash_t *cd_emission_struct_members; 350 1.1.1.2 christos 351 1.1.1.2 christos /* A set (a hash) of hash values of conflicting types. */ 352 1.1.1.2 christos ctf_dynset_t *cd_conflicting_types; 353 1.1.1.2 christos 354 1.1.1.2 christos /* A hash mapping fp *'s of inputs to their input_nums. Used only by 355 1.1.1.2 christos functions outside the core ctf_dedup / ctf_dedup_emit machinery which do 356 1.1.1.2 christos not take an inputs array. */ 357 1.1.1.2 christos ctf_dynhash_t *cd_input_nums; 358 1.1.1.2 christos 359 1.1.1.2 christos /* Maps type hashes to ctf_id_t's in this dictionary. Populated only at 360 1.1.1.2 christos emission time, in the dictionary where emission is taking place. */ 361 1.1.1.2 christos ctf_dynhash_t *cd_output_emission_hashes; 362 1.1.1.2 christos 363 1.1.1.2 christos /* Maps the decorated names of conflicted cross-TU forwards that were forcibly 364 1.1.1.2 christos emitted in this TU to their emitted ctf_id_ts. Populated only at emission 365 1.1.1.2 christos time, in the dictionary where emission is taking place. */ 366 1.1.1.2 christos ctf_dynhash_t *cd_output_emission_conflicted_forwards; 367 1.1.1.2 christos 368 1.1.1.2 christos /* Points to the output counterpart of this input dictionary, at emission 369 1.1.1.2 christos time. */ 370 1.1.1.2 christos ctf_dict_t *cd_output; 371 1.1.1.2 christos } ctf_dedup_t; 372 1.1 christos 373 1.1.1.2 christos /* The ctf_dict is the structure used to represent a CTF dictionary to library 374 1.1 christos clients, who see it only as an opaque pointer. Modifications can therefore 375 1.1 christos be made freely to this structure without regard to client versioning. The 376 1.1.1.2 christos ctf_dict_t typedef appears in <ctf-api.h> and declares a forward tag. 377 1.1.1.4 christos (A ctf_file_t typedef also appears there, for historical reasons.) */ 378 1.1.1.2 christos 379 1.1.1.2 christos struct ctf_dict 380 1.1.1.2 christos { 381 1.1.1.2 christos const ctf_dictops_t *ctf_dictops; /* Version-specific dict operations. */ 382 1.1.1.2 christos struct ctf_header *ctf_header; /* The header from this CTF dict. */ 383 1.1.1.2 christos unsigned char ctf_openflags; /* Flags the dict had when opened. */ 384 1.1 christos ctf_sect_t ctf_data; /* CTF data from object file. */ 385 1.1.1.4 christos ctf_sect_t ctf_ext_symtab; /* Symbol table from object file. */ 386 1.1.1.4 christos ctf_sect_t ctf_ext_strtab; /* String table from object file. */ 387 1.1.1.4 christos int ctf_symsect_little_endian; /* Endianness of the ctf_ext_symtab. */ 388 1.1.1.4 christos ctf_dynhash_t *ctf_symhash_func; /* (partial) hash, symsect name -> idx. */ 389 1.1.1.4 christos ctf_dynhash_t *ctf_symhash_objt; /* ditto, for object symbols. */ 390 1.1.1.2 christos size_t ctf_symhash_latest; /* Amount of symsect scanned so far. */ 391 1.1 christos ctf_dynhash_t *ctf_prov_strtab; /* Maps provisional-strtab offsets 392 1.1 christos to names. */ 393 1.1 christos ctf_dynhash_t *ctf_syn_ext_strtab; /* Maps ext-strtab offsets to names. */ 394 1.1 christos void *ctf_data_mmapped; /* CTF data we mmapped, to free later. */ 395 1.1 christos size_t ctf_data_mmapped_len; /* Length of CTF data we mmapped. */ 396 1.1.1.4 christos ctf_dynhash_t *ctf_structs; /* Hash table of struct types. */ 397 1.1.1.4 christos ctf_dynhash_t *ctf_unions; /* Hash table of union types. */ 398 1.1.1.4 christos ctf_dynhash_t *ctf_enums; /* Hash table of enum types. */ 399 1.1.1.4 christos ctf_dynhash_t *ctf_names; /* Hash table of remaining types, plus 400 1.1.1.4 christos enumeration constants. */ 401 1.1 christos ctf_lookup_t ctf_lookups[5]; /* Pointers to nametabs for name lookup. */ 402 1.1 christos ctf_strs_t ctf_str[2]; /* Array of string table base and bounds. */ 403 1.1.1.4 christos ctf_strs_writable_t *ctf_dynstrtab; /* Dynamically allocated string table, if any. */ 404 1.1.1.4 christos ctf_dynhash_t *ctf_str_atoms; /* Hash table of ctf_str_atoms_t. */ 405 1.1.1.4 christos ctf_dynhash_t *ctf_str_movable_refs; /* Hash table of void * -> ctf_str_atom_ref_movable_t. */ 406 1.1 christos uint32_t ctf_str_prov_offset; /* Latest provisional offset assigned so far. */ 407 1.1 christos unsigned char *ctf_base; /* CTF file pointer. */ 408 1.1 christos unsigned char *ctf_dynbase; /* Freeable CTF file pointer. */ 409 1.1 christos unsigned char *ctf_buf; /* Uncompressed CTF data buffer. */ 410 1.1 christos size_t ctf_size; /* Size of CTF header + uncompressed data. */ 411 1.1.1.2 christos uint32_t *ctf_sxlate; /* Translation table for unindexed symtypetab 412 1.1.1.2 christos entries. */ 413 1.1 christos unsigned long ctf_nsyms; /* Number of entries in symtab xlate table. */ 414 1.1 christos uint32_t *ctf_txlate; /* Translation table for type IDs. */ 415 1.1 christos uint32_t *ctf_ptrtab; /* Translation table for pointer-to lookups. */ 416 1.1 christos size_t ctf_ptrtab_len; /* Num types storable in ptrtab currently. */ 417 1.1.1.2 christos uint32_t *ctf_pptrtab; /* Parent types pointed to by child dicts. */ 418 1.1.1.2 christos size_t ctf_pptrtab_len; /* Num types storable in pptrtab currently. */ 419 1.1.1.2 christos uint32_t ctf_pptrtab_typemax; /* Max child type when pptrtab last updated. */ 420 1.1.1.4 christos ctf_dynset_t *ctf_conflicting_enums; /* Tracks enum constants that conflict. */ 421 1.1.1.2 christos uint32_t *ctf_funcidx_names; /* Name of each function symbol in symtypetab 422 1.1.1.2 christos (if indexed). */ 423 1.1.1.2 christos uint32_t *ctf_objtidx_names; /* Likewise, for object symbols. */ 424 1.1.1.2 christos size_t ctf_nfuncidx; /* Number of funcidx entries. */ 425 1.1.1.2 christos uint32_t *ctf_funcidx_sxlate; /* Offsets into funcinfo for a given funcidx. */ 426 1.1.1.2 christos uint32_t *ctf_objtidx_sxlate; /* Likewise, for ctf_objtidx. */ 427 1.1.1.2 christos size_t ctf_nobjtidx; /* Number of objtidx entries. */ 428 1.1.1.4 christos ctf_dynhash_t *ctf_objthash; /* Dynamic: name -> type ID. */ 429 1.1.1.4 christos ctf_dynhash_t *ctf_funchash; /* Dynamic: name -> CTF_K_FUNCTION type ID. */ 430 1.1.1.2 christos 431 1.1.1.2 christos /* The next three are linker-derived state found in ctf_link targets only. */ 432 1.1.1.2 christos 433 1.1.1.2 christos ctf_dynhash_t *ctf_dynsyms; /* Symbol info from ctf_link_shuffle_syms. */ 434 1.1.1.2 christos ctf_link_sym_t **ctf_dynsymidx; /* Indexes ctf_dynsyms by symidx. */ 435 1.1.1.2 christos uint32_t ctf_dynsymmax; /* Maximum ctf_dynsym index. */ 436 1.1.1.2 christos ctf_list_t ctf_in_flight_dynsyms; /* Dynsyms during accumulation. */ 437 1.1 christos struct ctf_varent *ctf_vars; /* Sorted variable->type mapping. */ 438 1.1 christos unsigned long ctf_nvars; /* Number of variables in ctf_vars. */ 439 1.1 christos unsigned long ctf_typemax; /* Maximum valid type ID number. */ 440 1.1.1.4 christos unsigned long ctf_stypes; /* Number of static (non-dynamic) types. */ 441 1.1 christos const ctf_dmodel_t *ctf_dmodel; /* Data model pointer (see above). */ 442 1.1 christos const char *ctf_cuname; /* Compilation unit name (if any). */ 443 1.1 christos char *ctf_dyncuname; /* Dynamically allocated name of CU. */ 444 1.1.1.2 christos struct ctf_dict *ctf_parent; /* Parent CTF dict (if any). */ 445 1.1.1.2 christos int ctf_parent_unreffed; /* Parent set by ctf_import_unref? */ 446 1.1.1.2 christos const char *ctf_parlabel; /* Label in parent dict (if any). */ 447 1.1 christos const char *ctf_parname; /* Basename of parent (if any). */ 448 1.1 christos char *ctf_dynparname; /* Dynamically allocated name of parent. */ 449 1.1 christos uint32_t ctf_parmax; /* Highest type ID of a parent type. */ 450 1.1 christos uint32_t ctf_refcnt; /* Reference count (for parent links). */ 451 1.1 christos uint32_t ctf_flags; /* Libctf flags (see below). */ 452 1.1 christos int ctf_errno; /* Error code for most recent error. */ 453 1.1 christos int ctf_version; /* CTF data version. */ 454 1.1 christos ctf_dynhash_t *ctf_dthash; /* Hash of dynamic type definitions. */ 455 1.1 christos ctf_list_t ctf_dtdefs; /* List of dynamic type definitions. */ 456 1.1 christos ctf_dynhash_t *ctf_dvhash; /* Hash of dynamic variable mappings. */ 457 1.1 christos ctf_list_t ctf_dvdefs; /* List of dynamic variable definitions. */ 458 1.1 christos unsigned long ctf_dtoldid; /* Oldest id that has been committed. */ 459 1.1 christos unsigned long ctf_snapshots; /* ctf_snapshot() plus ctf_update() count. */ 460 1.1 christos unsigned long ctf_snapshot_lu; /* ctf_snapshot() call count at last update. */ 461 1.1.1.2 christos ctf_archive_t *ctf_archive; /* Archive this ctf_dict_t came from. */ 462 1.1.1.2 christos ctf_list_t ctf_errs_warnings; /* CTF errors and warnings. */ 463 1.1 christos ctf_dynhash_t *ctf_link_inputs; /* Inputs to this link. */ 464 1.1 christos ctf_dynhash_t *ctf_link_outputs; /* Additional outputs from this link. */ 465 1.1.1.2 christos 466 1.1.1.2 christos /* If a link input CU, points at the corresponding per-CU output (if any); 467 1.1.1.2 christos if an output, points at the input (if any). */ 468 1.1.1.2 christos ctf_dict_t *ctf_link_in_out; 469 1.1.1.2 christos 470 1.1.1.2 christos /* Map input types to output types for ctf_add_type. Key is a 471 1.1.1.2 christos ctf_link_type_key_t: value is a type ID. */ 472 1.1.1.2 christos ctf_dynhash_t *ctf_link_type_mapping; 473 1.1.1.2 christos 474 1.1.1.2 christos /* Map input CU names to output CTF dict names: populated in the top-level 475 1.1.1.2 christos output dict. 476 1.1.1.2 christos 477 1.1.1.2 christos Key and value are dynamically-allocated strings. */ 478 1.1.1.2 christos ctf_dynhash_t *ctf_link_in_cu_mapping; 479 1.1.1.2 christos 480 1.1.1.2 christos /* Map output CTF dict names to input CU names: populated in the top-level 481 1.1.1.2 christos output dict. A hash of string to hash (set) of strings. Key and 482 1.1.1.2 christos individual value members are shared with ctf_link_in_cu_mapping. */ 483 1.1.1.2 christos ctf_dynhash_t *ctf_link_out_cu_mapping; 484 1.1.1.2 christos 485 1.1.1.2 christos /* CTF linker flags. Set on the parent output dict (the one passed to 486 1.1.1.2 christos ctf_link). Only respected when LCTF_LINKING set in ctf_flags. */ 487 1.1.1.2 christos int ctf_link_flags; 488 1.1.1.2 christos 489 1.1.1.2 christos /* Allow the caller to change the name of link archive members. */ 490 1.1 christos ctf_link_memb_name_changer_f *ctf_link_memb_name_changer; 491 1.1.1.2 christos void *ctf_link_memb_name_changer_arg; /* Argument for it. */ 492 1.1.1.2 christos 493 1.1.1.2 christos /* Allow the caller to filter out variables they don't care about. */ 494 1.1.1.2 christos ctf_link_variable_filter_f *ctf_link_variable_filter; 495 1.1.1.2 christos void *ctf_link_variable_filter_arg; /* Argument for it. */ 496 1.1.1.2 christos 497 1.1 christos ctf_dynhash_t *ctf_add_processing; /* Types ctf_add_type is working on now. */ 498 1.1.1.2 christos 499 1.1.1.2 christos /* Atoms table for dedup string storage. All strings in the ctf_dedup_t are 500 1.1.1.2 christos stored here. Only the _alloc copy is allocated or freed: the 501 1.1.1.2 christos ctf_dedup_atoms may be pointed to some other CTF dict, to share its atoms. 502 1.1.1.2 christos We keep the atoms table outside the ctf_dedup so that atoms can be 503 1.1.1.2 christos preserved across multiple similar links, such as when doing cu-mapped 504 1.1.1.2 christos links. */ 505 1.1.1.2 christos ctf_dynset_t *ctf_dedup_atoms; 506 1.1.1.2 christos ctf_dynset_t *ctf_dedup_atoms_alloc; 507 1.1.1.2 christos 508 1.1.1.2 christos ctf_dedup_t ctf_dedup; /* Deduplicator state. */ 509 1.1.1.2 christos 510 1.1 christos char *ctf_tmp_typeslice; /* Storage for slicing up type names. */ 511 1.1 christos size_t ctf_tmp_typeslicelen; /* Size of the typeslice. */ 512 1.1 christos void *ctf_specific; /* Data for ctf_get/setspecific(). */ 513 1.1 christos }; 514 1.1 christos 515 1.1.1.2 christos /* An abstraction over both a ctf_dict_t and a ctf_archive_t. */ 516 1.1 christos 517 1.1 christos struct ctf_archive_internal 518 1.1 christos { 519 1.1 christos int ctfi_is_archive; 520 1.1.1.2 christos int ctfi_unmap_on_close; 521 1.1.1.2 christos ctf_dict_t *ctfi_dict; 522 1.1 christos struct ctf_archive *ctfi_archive; 523 1.1.1.2 christos ctf_dynhash_t *ctfi_dicts; /* Dicts we have opened and cached. */ 524 1.1.1.2 christos ctf_dict_t *ctfi_crossdict_cache; /* Cross-dict caching. */ 525 1.1.1.2 christos ctf_dict_t **ctfi_symdicts; /* Array of index -> ctf_dict_t *. */ 526 1.1.1.2 christos ctf_dynhash_t *ctfi_symnamedicts; /* Hash of name -> ctf_dict_t *. */ 527 1.1 christos ctf_sect_t ctfi_symsect; 528 1.1.1.2 christos int ctfi_symsect_little_endian; /* -1 for unknown / do not set. */ 529 1.1 christos ctf_sect_t ctfi_strsect; 530 1.1.1.2 christos int ctfi_free_symsect; 531 1.1.1.2 christos int ctfi_free_strsect; 532 1.1 christos void *ctfi_data; 533 1.1.1.2 christos bfd *ctfi_abfd; /* Optional source of section data. */ 534 1.1 christos void (*ctfi_bfd_close) (struct ctf_archive_internal *); 535 1.1 christos }; 536 1.1 christos 537 1.1.1.2 christos /* Iterator state for the *_next() functions. */ 538 1.1.1.2 christos 539 1.1.1.2 christos /* A single hash key/value pair. */ 540 1.1.1.2 christos typedef struct ctf_next_hkv 541 1.1.1.2 christos { 542 1.1.1.2 christos void *hkv_key; 543 1.1.1.2 christos void *hkv_value; 544 1.1.1.2 christos } ctf_next_hkv_t; 545 1.1.1.2 christos 546 1.1.1.2 christos struct ctf_next 547 1.1.1.2 christos { 548 1.1.1.2 christos void (*ctn_iter_fun) (void); 549 1.1.1.2 christos ctf_id_t ctn_type; 550 1.1.1.2 christos ssize_t ctn_size; 551 1.1.1.2 christos ssize_t ctn_increment; 552 1.1.1.2 christos const ctf_type_t *ctn_tp; 553 1.1.1.2 christos uint32_t ctn_n; 554 1.1.1.2 christos 555 1.1.1.2 christos /* Some iterators contain other iterators, in addition to their other 556 1.1.1.4 christos state. We allow for inner and outer iterators, for two-layer nested loops 557 1.1.1.4 christos like those found in ctf_arc_lookup_enumerator_next. */ 558 1.1.1.2 christos ctf_next_t *ctn_next; 559 1.1.1.4 christos ctf_next_t *ctn_next_inner; 560 1.1.1.2 christos 561 1.1.1.4 christos /* We can save space on this side of things by noting that a type is either 562 1.1.1.4 christos dynamic or not, as a whole, and a given iterator can only iterate over one 563 1.1.1.4 christos kind of thing at once: so we can overlap the DTD and non-DTD members, and 564 1.1.1.4 christos the structure, variable and enum members, etc. */ 565 1.1.1.2 christos union 566 1.1.1.2 christos { 567 1.1.1.2 christos unsigned char *ctn_vlen; 568 1.1.1.2 christos const ctf_enum_t *ctn_en; 569 1.1.1.2 christos const ctf_dvdef_t *ctn_dvd; 570 1.1.1.2 christos ctf_next_hkv_t *ctn_sorted_hkv; 571 1.1.1.2 christos void **ctn_hash_slot; 572 1.1.1.2 christos } u; 573 1.1.1.2 christos 574 1.1.1.4 christos /* This union is of various sorts of dict we can iterate over: currently 575 1.1.1.4 christos archives, dictionaries, dynhashes, and dynsets. ctn_fp is non-const 576 1.1.1.4 christos because we need to set errors on it. */ 577 1.1.1.4 christos 578 1.1.1.2 christos union 579 1.1.1.2 christos { 580 1.1.1.4 christos ctf_dict_t *ctn_fp; 581 1.1.1.2 christos const ctf_archive_t *ctn_arc; 582 1.1.1.2 christos const ctf_dynhash_t *ctn_h; 583 1.1.1.2 christos const ctf_dynset_t *ctn_s; 584 1.1.1.2 christos } cu; 585 1.1.1.2 christos }; 586 1.1.1.2 christos 587 1.1 christos /* Return x rounded up to an alignment boundary. 588 1.1 christos eg, P2ROUNDUP(0x1234, 0x100) == 0x1300 (0x13*align) 589 1.1 christos eg, P2ROUNDUP(0x5600, 0x100) == 0x5600 (0x56*align) */ 590 1.1 christos #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 591 1.1 christos 592 1.1 christos /* * If an offs is not aligned already then round it up and align it. */ 593 1.1 christos #define LCTF_ALIGN_OFFS(offs, align) ((offs + (align - 1)) & ~(align - 1)) 594 1.1 christos 595 1.1 christos #define LCTF_TYPE_ISPARENT(fp, id) ((id) <= fp->ctf_parmax) 596 1.1 christos #define LCTF_TYPE_ISCHILD(fp, id) ((id) > fp->ctf_parmax) 597 1.1 christos #define LCTF_TYPE_TO_INDEX(fp, id) ((id) & (fp->ctf_parmax)) 598 1.1 christos #define LCTF_INDEX_TO_TYPE(fp, id, child) (child ? ((id) | (fp->ctf_parmax+1)) : \ 599 1.1 christos (id)) 600 1.1 christos 601 1.1 christos #define LCTF_INDEX_TO_TYPEPTR(fp, i) \ 602 1.1.1.4 christos ((i > fp->ctf_stypes) ? \ 603 1.1 christos &(ctf_dtd_lookup (fp, LCTF_INDEX_TO_TYPE \ 604 1.1 christos (fp, i, fp->ctf_flags & LCTF_CHILD))->dtd_data) : \ 605 1.1 christos (ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)])) 606 1.1 christos 607 1.1.1.2 christos #define LCTF_INFO_KIND(fp, info) ((fp)->ctf_dictops->ctfo_get_kind(info)) 608 1.1.1.2 christos #define LCTF_INFO_ISROOT(fp, info) ((fp)->ctf_dictops->ctfo_get_root(info)) 609 1.1.1.2 christos #define LCTF_INFO_VLEN(fp, info) ((fp)->ctf_dictops->ctfo_get_vlen(info)) 610 1.1 christos #define LCTF_VBYTES(fp, kind, size, vlen) \ 611 1.1.1.2 christos ((fp)->ctf_dictops->ctfo_get_vbytes(fp, kind, size, vlen)) 612 1.1 christos 613 1.1.1.2 christos #define LCTF_CHILD 0x0001 /* CTF dict is a child. */ 614 1.1.1.4 christos #define LCTF_LINKING 0x0002 /* CTF link is underway: respect ctf_link_flags. */ 615 1.1.1.4 christos #define LCTF_STRICT_NO_DUP_ENUMERATORS 0x0004 /* Duplicate enums prohibited. */ 616 1.1.1.2 christos 617 1.1.1.4 christos extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, int); 618 1.1.1.2 christos extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t); 619 1.1.1.4 christos extern ctf_id_t ctf_lookup_variable_here (ctf_dict_t *fp, const char *name); 620 1.1.1.4 christos extern ctf_id_t ctf_lookup_by_sym_or_name (ctf_dict_t *, unsigned long symidx, 621 1.1.1.4 christos const char *symname, int try_parent, 622 1.1.1.4 christos int is_function); 623 1.1.1.2 christos extern ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *, int, const char *); 624 1.1.1.2 christos extern void ctf_set_ctl_hashes (ctf_dict_t *); 625 1.1.1.4 christos extern ctf_id_t ctf_symbol_next_static (ctf_dict_t *, ctf_next_t **, 626 1.1.1.4 christos const char **, int); 627 1.1.1.2 christos 628 1.1.1.2 christos extern int ctf_symtab_skippable (ctf_link_sym_t *sym); 629 1.1.1.2 christos extern int ctf_add_funcobjt_sym (ctf_dict_t *, int is_function, 630 1.1.1.2 christos const char *, ctf_id_t); 631 1.1 christos 632 1.1.1.2 christos extern ctf_dict_t *ctf_get_dict (ctf_dict_t *fp, ctf_id_t type); 633 1.1 christos 634 1.1 christos typedef unsigned int (*ctf_hash_fun) (const void *ptr); 635 1.1 christos extern unsigned int ctf_hash_integer (const void *ptr); 636 1.1 christos extern unsigned int ctf_hash_string (const void *ptr); 637 1.1.1.2 christos extern unsigned int ctf_hash_type_key (const void *ptr); 638 1.1.1.2 christos extern unsigned int ctf_hash_type_id_key (const void *ptr); 639 1.1 christos 640 1.1 christos typedef int (*ctf_hash_eq_fun) (const void *, const void *); 641 1.1 christos extern int ctf_hash_eq_integer (const void *, const void *); 642 1.1 christos extern int ctf_hash_eq_string (const void *, const void *); 643 1.1.1.2 christos extern int ctf_hash_eq_type_key (const void *, const void *); 644 1.1.1.2 christos extern int ctf_hash_eq_type_id_key (const void *, const void *); 645 1.1 christos 646 1.1 christos typedef void (*ctf_hash_free_fun) (void *); 647 1.1 christos 648 1.1 christos typedef void (*ctf_hash_iter_f) (void *key, void *value, void *arg); 649 1.1 christos typedef int (*ctf_hash_iter_remove_f) (void *key, void *value, void *arg); 650 1.1.1.2 christos typedef int (*ctf_hash_iter_find_f) (void *key, void *value, void *arg); 651 1.1.1.2 christos typedef int (*ctf_hash_sort_f) (const ctf_next_hkv_t *, const ctf_next_hkv_t *, 652 1.1.1.2 christos void *arg); 653 1.1 christos 654 1.1 christos extern ctf_dynhash_t *ctf_dynhash_create (ctf_hash_fun, ctf_hash_eq_fun, 655 1.1 christos ctf_hash_free_fun, ctf_hash_free_fun); 656 1.1.1.4 christos extern ctf_dynhash_t *ctf_dynhash_create_sized (unsigned long, ctf_hash_fun, 657 1.1.1.4 christos ctf_hash_eq_fun, 658 1.1.1.4 christos ctf_hash_free_fun, 659 1.1.1.4 christos ctf_hash_free_fun); 660 1.1.1.4 christos 661 1.1 christos extern int ctf_dynhash_insert (ctf_dynhash_t *, void *, void *); 662 1.1 christos extern void ctf_dynhash_remove (ctf_dynhash_t *, const void *); 663 1.1.1.2 christos extern size_t ctf_dynhash_elements (ctf_dynhash_t *); 664 1.1 christos extern void ctf_dynhash_empty (ctf_dynhash_t *); 665 1.1.1.4 christos extern int ctf_dynhash_insert_type (ctf_dict_t *, ctf_dynhash_t *, uint32_t, uint32_t); 666 1.1.1.4 christos extern ctf_id_t ctf_dynhash_lookup_type (ctf_dynhash_t *, const char *); 667 1.1 christos extern void *ctf_dynhash_lookup (ctf_dynhash_t *, const void *); 668 1.1.1.2 christos extern int ctf_dynhash_lookup_kv (ctf_dynhash_t *, const void *key, 669 1.1.1.2 christos const void **orig_key, void **value); 670 1.1 christos extern void ctf_dynhash_destroy (ctf_dynhash_t *); 671 1.1 christos extern void ctf_dynhash_iter (ctf_dynhash_t *, ctf_hash_iter_f, void *); 672 1.1 christos extern void ctf_dynhash_iter_remove (ctf_dynhash_t *, ctf_hash_iter_remove_f, 673 1.1 christos void *); 674 1.1.1.2 christos extern void *ctf_dynhash_iter_find (ctf_dynhash_t *, ctf_hash_iter_find_f, 675 1.1.1.2 christos void *); 676 1.1.1.2 christos extern int ctf_dynhash_sort_by_name (const ctf_next_hkv_t *, 677 1.1.1.2 christos const ctf_next_hkv_t *, 678 1.1.1.2 christos void * _libctf_unused_); 679 1.1.1.2 christos extern int ctf_dynhash_next (ctf_dynhash_t *, ctf_next_t **, 680 1.1.1.2 christos void **key, void **value); 681 1.1.1.2 christos extern int ctf_dynhash_next_sorted (ctf_dynhash_t *, ctf_next_t **, 682 1.1.1.2 christos void **key, void **value, ctf_hash_sort_f, 683 1.1.1.2 christos void *); 684 1.1.1.4 christos extern int ctf_dynhash_next_remove (ctf_next_t * const *); 685 1.1.1.2 christos 686 1.1.1.2 christos extern ctf_dynset_t *ctf_dynset_create (htab_hash, htab_eq, ctf_hash_free_fun); 687 1.1.1.2 christos extern int ctf_dynset_insert (ctf_dynset_t *, void *); 688 1.1.1.2 christos extern void ctf_dynset_remove (ctf_dynset_t *, const void *); 689 1.1.1.4 christos extern size_t ctf_dynset_elements (ctf_dynset_t *); 690 1.1.1.2 christos extern void ctf_dynset_destroy (ctf_dynset_t *); 691 1.1.1.2 christos extern void *ctf_dynset_lookup (ctf_dynset_t *, const void *); 692 1.1.1.2 christos extern int ctf_dynset_exists (ctf_dynset_t *, const void *key, 693 1.1.1.2 christos const void **orig_key); 694 1.1.1.2 christos extern int ctf_dynset_next (ctf_dynset_t *, ctf_next_t **, void **key); 695 1.1.1.2 christos extern void *ctf_dynset_lookup_any (ctf_dynset_t *); 696 1.1.1.2 christos 697 1.1.1.2 christos extern void ctf_sha1_init (ctf_sha1_t *); 698 1.1.1.2 christos extern void ctf_sha1_add (ctf_sha1_t *, const void *, size_t); 699 1.1.1.2 christos extern char *ctf_sha1_fini (ctf_sha1_t *, char *); 700 1.1 christos 701 1.1 christos #define ctf_list_prev(elem) ((void *)(((ctf_list_t *)(elem))->l_prev)) 702 1.1 christos #define ctf_list_next(elem) ((void *)(((ctf_list_t *)(elem))->l_next)) 703 1.1 christos 704 1.1 christos extern void ctf_list_append (ctf_list_t *, void *); 705 1.1 christos extern void ctf_list_prepend (ctf_list_t *, void *); 706 1.1 christos extern void ctf_list_delete (ctf_list_t *, void *); 707 1.1.1.2 christos extern void ctf_list_splice (ctf_list_t *, ctf_list_t *); 708 1.1 christos extern int ctf_list_empty_p (ctf_list_t *lp); 709 1.1 christos 710 1.1.1.2 christos extern int ctf_dtd_insert (ctf_dict_t *, ctf_dtdef_t *, int flag, int kind); 711 1.1.1.2 christos extern void ctf_dtd_delete (ctf_dict_t *, ctf_dtdef_t *); 712 1.1.1.2 christos extern ctf_dtdef_t *ctf_dtd_lookup (const ctf_dict_t *, ctf_id_t); 713 1.1.1.2 christos extern ctf_dtdef_t *ctf_dynamic_type (const ctf_dict_t *, ctf_id_t); 714 1.1.1.2 christos 715 1.1.1.2 christos extern int ctf_dvd_insert (ctf_dict_t *, ctf_dvdef_t *); 716 1.1.1.2 christos extern void ctf_dvd_delete (ctf_dict_t *, ctf_dvdef_t *); 717 1.1.1.2 christos extern ctf_dvdef_t *ctf_dvd_lookup (const ctf_dict_t *, const char *); 718 1.1.1.2 christos 719 1.1.1.2 christos extern ctf_id_t ctf_add_encoded (ctf_dict_t *, uint32_t, const char *, 720 1.1.1.2 christos const ctf_encoding_t *, uint32_t kind); 721 1.1.1.2 christos extern ctf_id_t ctf_add_reftype (ctf_dict_t *, uint32_t, ctf_id_t, 722 1.1.1.2 christos uint32_t kind); 723 1.1.1.4 christos extern int ctf_add_variable_forced (ctf_dict_t *, const char *, ctf_id_t); 724 1.1.1.4 christos extern int ctf_add_funcobjt_sym_forced (ctf_dict_t *, int is_function, 725 1.1.1.4 christos const char *, ctf_id_t); 726 1.1.1.4 christos 727 1.1.1.4 christos extern int ctf_track_enumerator (ctf_dict_t *, ctf_id_t, const char *); 728 1.1.1.2 christos 729 1.1.1.2 christos extern int ctf_dedup_atoms_init (ctf_dict_t *); 730 1.1.1.2 christos extern int ctf_dedup (ctf_dict_t *, ctf_dict_t **, uint32_t ninputs, 731 1.1.1.4 christos int cu_mapped_phase); 732 1.1.1.2 christos extern ctf_dict_t **ctf_dedup_emit (ctf_dict_t *, ctf_dict_t **, 733 1.1.1.2 christos uint32_t ninputs, uint32_t *parents, 734 1.1.1.4 christos uint32_t *noutputs, int cu_mapped_phase); 735 1.1.1.4 christos extern void ctf_dedup_fini (ctf_dict_t *, ctf_dict_t **, uint32_t); 736 1.1.1.2 christos extern ctf_id_t ctf_dedup_type_mapping (ctf_dict_t *fp, ctf_dict_t *src_fp, 737 1.1.1.2 christos ctf_id_t src_type); 738 1.1 christos 739 1.1 christos extern void ctf_decl_init (ctf_decl_t *); 740 1.1 christos extern void ctf_decl_fini (ctf_decl_t *); 741 1.1.1.2 christos extern void ctf_decl_push (ctf_decl_t *, ctf_dict_t *, ctf_id_t); 742 1.1 christos 743 1.1 christos _libctf_printflike_ (2, 3) 744 1.1 christos extern void ctf_decl_sprintf (ctf_decl_t *, const char *, ...); 745 1.1 christos extern char *ctf_decl_buf (ctf_decl_t *cd); 746 1.1 christos 747 1.1.1.2 christos extern const char *ctf_strptr (ctf_dict_t *, uint32_t); 748 1.1.1.2 christos extern const char *ctf_strraw (ctf_dict_t *, uint32_t); 749 1.1.1.2 christos extern const char *ctf_strraw_explicit (ctf_dict_t *, uint32_t, 750 1.1 christos ctf_strs_t *); 751 1.1.1.4 christos extern const char *ctf_strptr_validate (ctf_dict_t *, uint32_t); 752 1.1.1.2 christos extern int ctf_str_create_atoms (ctf_dict_t *); 753 1.1.1.2 christos extern void ctf_str_free_atoms (ctf_dict_t *); 754 1.1.1.2 christos extern uint32_t ctf_str_add (ctf_dict_t *, const char *); 755 1.1.1.2 christos extern uint32_t ctf_str_add_ref (ctf_dict_t *, const char *, uint32_t *ref); 756 1.1.1.4 christos extern uint32_t ctf_str_add_movable_ref (ctf_dict_t *, const char *, 757 1.1.1.4 christos uint32_t *ref); 758 1.1.1.4 christos extern int ctf_str_move_refs (ctf_dict_t *fp, void *src, size_t len, void *dest); 759 1.1.1.2 christos extern int ctf_str_add_external (ctf_dict_t *, const char *, uint32_t offset); 760 1.1.1.2 christos extern void ctf_str_remove_ref (ctf_dict_t *, const char *, uint32_t *ref); 761 1.1.1.2 christos extern void ctf_str_rollback (ctf_dict_t *, ctf_snapshot_id_t); 762 1.1.1.4 christos extern const ctf_strs_writable_t *ctf_str_write_strtab (ctf_dict_t *); 763 1.1.1.2 christos 764 1.1.1.2 christos extern struct ctf_archive_internal * 765 1.1.1.2 christos ctf_new_archive_internal (int is_archive, int unmap_on_close, 766 1.1.1.2 christos struct ctf_archive *, ctf_dict_t *, 767 1.1.1.2 christos const ctf_sect_t *symsect, 768 1.1.1.2 christos const ctf_sect_t *strsect, int *errp); 769 1.1 christos extern struct ctf_archive *ctf_arc_open_internal (const char *, int *); 770 1.1 christos extern void ctf_arc_close_internal (struct ctf_archive *); 771 1.1.1.2 christos extern const ctf_preamble_t *ctf_arc_bufpreamble (const ctf_sect_t *); 772 1.1 christos extern void *ctf_set_open_errno (int *, int); 773 1.1.1.2 christos extern void ctf_flip_header (ctf_header_t *); 774 1.1.1.2 christos extern int ctf_flip (ctf_dict_t *, ctf_header_t *, unsigned char *, int); 775 1.1 christos 776 1.1.1.2 christos extern int ctf_import_unref (ctf_dict_t *fp, ctf_dict_t *pfp); 777 1.1.1.4 christos 778 1.1.1.4 christos extern int ctf_write_thresholded (ctf_dict_t *fp, int fd, size_t threshold); 779 1.1 christos 780 1.1 christos _libctf_malloc_ 781 1.1 christos extern void *ctf_mmap (size_t length, size_t offset, int fd); 782 1.1 christos extern void ctf_munmap (void *, size_t); 783 1.1 christos extern ssize_t ctf_pread (int fd, void *buf, ssize_t count, off_t offset); 784 1.1 christos 785 1.1 christos extern char *ctf_str_append (char *, const char *); 786 1.1 christos extern char *ctf_str_append_noerr (char *, const char *); 787 1.1 christos 788 1.1.1.2 christos extern ctf_id_t ctf_type_resolve_unsliced (ctf_dict_t *, ctf_id_t); 789 1.1.1.2 christos extern int ctf_type_kind_unsliced (ctf_dict_t *, ctf_id_t); 790 1.1 christos 791 1.1 christos _libctf_printflike_ (1, 2) 792 1.1 christos extern void ctf_dprintf (const char *, ...); 793 1.1 christos extern void libctf_init_debug (void); 794 1.1 christos 795 1.1.1.2 christos _libctf_printflike_ (4, 5) 796 1.1.1.2 christos extern void ctf_err_warn (ctf_dict_t *, int is_warning, int err, 797 1.1.1.2 christos const char *, ...); 798 1.1.1.2 christos extern void ctf_err_warn_to_open (ctf_dict_t *); 799 1.1.1.2 christos extern void ctf_assert_fail_internal (ctf_dict_t *, const char *, 800 1.1.1.2 christos size_t, const char *); 801 1.1.1.2 christos extern const char *ctf_link_input_name (ctf_dict_t *); 802 1.1.1.2 christos 803 1.1.1.2 christos extern ctf_link_sym_t *ctf_elf32_to_link_sym (ctf_dict_t *fp, ctf_link_sym_t *dst, 804 1.1.1.2 christos const Elf32_Sym *src, uint32_t symidx); 805 1.1.1.2 christos extern ctf_link_sym_t *ctf_elf64_to_link_sym (ctf_dict_t *fp, ctf_link_sym_t *dst, 806 1.1.1.2 christos const Elf64_Sym *src, uint32_t symidx); 807 1.1 christos 808 1.1 christos /* Variables, all underscore-prepended. */ 809 1.1 christos 810 1.1 christos extern const char _CTF_SECTION[]; /* name of CTF ELF section */ 811 1.1 christos extern const char _CTF_NULLSTR[]; /* empty string */ 812 1.1 christos 813 1.1 christos extern int _libctf_version; /* library client version */ 814 1.1 christos extern int _libctf_debug; /* debugging messages enabled */ 815 1.1 christos 816 1.1.1.2 christos #include "ctf-inlines.h" 817 1.1.1.2 christos 818 1.1 christos #ifdef __cplusplus 819 1.1 christos } 820 1.1 christos #endif 821 1.1 christos 822 1.1 christos #endif /* _CTF_IMPL_H */ 823