18dffb485Schristos /* Implementation header. 2*c9055873Schristos Copyright (C) 2019-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This file is part of libctf. 58dffb485Schristos 68dffb485Schristos libctf is free software; you can redistribute it and/or modify it under 78dffb485Schristos the terms of the GNU General Public License as published by the Free 88dffb485Schristos Software Foundation; either version 3, or (at your option) any later 98dffb485Schristos version. 108dffb485Schristos 118dffb485Schristos This program is distributed in the hope that it will be useful, but 128dffb485Schristos WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 148dffb485Schristos See the GNU General Public License for more details. 158dffb485Schristos 168dffb485Schristos You should have received a copy of the GNU General Public License 178dffb485Schristos along with this program; see the file COPYING. If not see 188dffb485Schristos <http://www.gnu.org/licenses/>. */ 198dffb485Schristos 208dffb485Schristos #ifndef _CTF_IMPL_H 218dffb485Schristos #define _CTF_IMPL_H 228dffb485Schristos 238dffb485Schristos #include "config.h" 248dffb485Schristos #include <errno.h> 258dffb485Schristos #include <sys/param.h> 268dffb485Schristos #include "ctf-decls.h" 278dffb485Schristos #include <ctf-api.h> 288dffb485Schristos #include "ctf-sha1.h" 298dffb485Schristos #include <sys/types.h> 308dffb485Schristos #include <stdlib.h> 318dffb485Schristos #include <stdarg.h> 324b169a6bSchristos #include <stddef.h> 338dffb485Schristos #include <stdio.h> 348dffb485Schristos #include <stdint.h> 354b169a6bSchristos #include <string.h> 368dffb485Schristos #include <limits.h> 378dffb485Schristos #include <ctype.h> 388dffb485Schristos #include <elf.h> 398dffb485Schristos #include <bfd.h> 408dffb485Schristos #include "hashtab.h" 418dffb485Schristos #include "ctf-intl.h" 428dffb485Schristos 438dffb485Schristos #ifdef __cplusplus 448dffb485Schristos extern "C" 458dffb485Schristos { 468dffb485Schristos #endif 478dffb485Schristos 484b169a6bSchristos /* Tuning. */ 494b169a6bSchristos 504b169a6bSchristos /* The proportion of symtypetab entries which must be pads before we consider it 514b169a6bSchristos worthwhile to emit a symtypetab section as an index. Indexes cost time to 524b169a6bSchristos look up, but save space all told. Do not set to 1, since this will cause 534b169a6bSchristos indexes to be eschewed completely, even in child dicts, at considerable space 544b169a6bSchristos cost. */ 554b169a6bSchristos #define CTF_INDEX_PAD_THRESHOLD .75 564b169a6bSchristos 578dffb485Schristos /* Compiler attributes. */ 588dffb485Schristos 598dffb485Schristos #if defined (__GNUC__) 608dffb485Schristos 618dffb485Schristos /* GCC. We assume that all compilers claiming to be GCC support sufficiently 628dffb485Schristos many GCC attributes that the code below works. If some non-GCC compilers 638dffb485Schristos masquerading as GCC in fact do not implement these attributes, version checks 648dffb485Schristos may be required. */ 658dffb485Schristos 668dffb485Schristos /* We use the _libctf_*_ pattern to avoid clashes with any future attribute 678dffb485Schristos macros glibc may introduce, which have names of the pattern 688dffb485Schristos __attribute_blah__. */ 698dffb485Schristos 708dffb485Schristos #define _libctf_printflike_(string_index,first_to_check) \ 718dffb485Schristos __attribute__ ((__format__ (__printf__, (string_index), (first_to_check)))) 728dffb485Schristos #define _libctf_unlikely_(x) __builtin_expect ((x), 0) 738dffb485Schristos #define _libctf_unused_ __attribute__ ((__unused__)) 748dffb485Schristos #define _libctf_malloc_ __attribute__((__malloc__)) 754b169a6bSchristos #define _libctf_nonnull_(params) __attribute__((__nonnull__ params)) 768dffb485Schristos 778dffb485Schristos #else 788dffb485Schristos 798dffb485Schristos #define _libctf_printflike_(string_index,first_to_check) 808dffb485Schristos #define _libctf_unlikely_(x) (x) 818dffb485Schristos #define _libctf_unused_ 828dffb485Schristos #define _libctf_malloc_ 834b169a6bSchristos #define _libctf_nonnull_(params) 848dffb485Schristos #define __extension__ 858dffb485Schristos 868dffb485Schristos #endif 878dffb485Schristos 888dffb485Schristos #if defined (ENABLE_LIBCTF_HASH_DEBUGGING) && !defined (NDEBUG) 898dffb485Schristos #include <assert.h> 908dffb485Schristos #define ctf_assert(fp, expr) (assert (expr), 1) 918dffb485Schristos #else 928dffb485Schristos #define ctf_assert(fp, expr) \ 938dffb485Schristos _libctf_unlikely_ (ctf_assert_internal (fp, __FILE__, __LINE__, \ 948dffb485Schristos #expr, !!(expr))) 958dffb485Schristos #endif 968dffb485Schristos 978dffb485Schristos /* libctf in-memory state. */ 988dffb485Schristos 998dffb485Schristos typedef struct ctf_fixed_hash ctf_hash_t; /* Private to ctf-hash.c. */ 1008dffb485Schristos typedef struct ctf_dynhash ctf_dynhash_t; /* Private to ctf-hash.c. */ 1018dffb485Schristos typedef struct ctf_dynset ctf_dynset_t; /* Private to ctf-hash.c. */ 1028dffb485Schristos 1038dffb485Schristos typedef struct ctf_strs 1048dffb485Schristos { 1058dffb485Schristos const char *cts_strs; /* Base address of string table. */ 1068dffb485Schristos size_t cts_len; /* Size of string table in bytes. */ 1078dffb485Schristos } ctf_strs_t; 1088dffb485Schristos 1098dffb485Schristos typedef struct ctf_strs_writable 1108dffb485Schristos { 1118dffb485Schristos char *cts_strs; /* Base address of string table. */ 1128dffb485Schristos size_t cts_len; /* Size of string table in bytes. */ 1138dffb485Schristos } ctf_strs_writable_t; 1148dffb485Schristos 1158dffb485Schristos typedef struct ctf_dmodel 1168dffb485Schristos { 1178dffb485Schristos const char *ctd_name; /* Data model name. */ 1188dffb485Schristos int ctd_code; /* Data model code. */ 1198dffb485Schristos size_t ctd_pointer; /* Size of void * in bytes. */ 1208dffb485Schristos size_t ctd_char; /* Size of char in bytes. */ 1218dffb485Schristos size_t ctd_short; /* Size of short in bytes. */ 1228dffb485Schristos size_t ctd_int; /* Size of int in bytes. */ 1238dffb485Schristos size_t ctd_long; /* Size of long in bytes. */ 1248dffb485Schristos } ctf_dmodel_t; 1258dffb485Schristos 1268dffb485Schristos typedef struct ctf_lookup 1278dffb485Schristos { 1288dffb485Schristos const char *ctl_prefix; /* String prefix for this lookup. */ 1298dffb485Schristos size_t ctl_len; /* Length of prefix string in bytes. */ 130*c9055873Schristos ctf_dynhash_t *ctl_hash; /* Pointer to hash table for lookup. */ 1318dffb485Schristos } ctf_lookup_t; 1328dffb485Schristos 1334b169a6bSchristos typedef struct ctf_dictops 1348dffb485Schristos { 1358dffb485Schristos uint32_t (*ctfo_get_kind) (uint32_t); 1368dffb485Schristos uint32_t (*ctfo_get_root) (uint32_t); 1378dffb485Schristos uint32_t (*ctfo_get_vlen) (uint32_t); 1384b169a6bSchristos ssize_t (*ctfo_get_ctt_size) (const ctf_dict_t *, const ctf_type_t *, 1398dffb485Schristos ssize_t *, ssize_t *); 1404b169a6bSchristos ssize_t (*ctfo_get_vbytes) (ctf_dict_t *, unsigned short, ssize_t, size_t); 1414b169a6bSchristos } ctf_dictops_t; 1428dffb485Schristos 1438dffb485Schristos typedef struct ctf_list 1448dffb485Schristos { 1458dffb485Schristos struct ctf_list *l_prev; /* Previous pointer or tail pointer. */ 1468dffb485Schristos struct ctf_list *l_next; /* Next pointer or head pointer. */ 1478dffb485Schristos } ctf_list_t; 1488dffb485Schristos 1498dffb485Schristos typedef enum 1508dffb485Schristos { 1518dffb485Schristos CTF_PREC_BASE, 1528dffb485Schristos CTF_PREC_POINTER, 1538dffb485Schristos CTF_PREC_ARRAY, 1548dffb485Schristos CTF_PREC_FUNCTION, 1558dffb485Schristos CTF_PREC_MAX 1568dffb485Schristos } ctf_decl_prec_t; 1578dffb485Schristos 1588dffb485Schristos typedef struct ctf_decl_node 1598dffb485Schristos { 1608dffb485Schristos ctf_list_t cd_list; /* Linked list pointers. */ 1618dffb485Schristos ctf_id_t cd_type; /* Type identifier. */ 1628dffb485Schristos uint32_t cd_kind; /* Type kind. */ 1638dffb485Schristos uint32_t cd_n; /* Type dimension if array. */ 1648dffb485Schristos } ctf_decl_node_t; 1658dffb485Schristos 1668dffb485Schristos typedef struct ctf_decl 1678dffb485Schristos { 1688dffb485Schristos ctf_list_t cd_nodes[CTF_PREC_MAX]; /* Declaration node stacks. */ 1698dffb485Schristos int cd_order[CTF_PREC_MAX]; /* Storage order of decls. */ 1708dffb485Schristos ctf_decl_prec_t cd_qualp; /* Qualifier precision. */ 1718dffb485Schristos ctf_decl_prec_t cd_ordp; /* Ordered precision. */ 1728dffb485Schristos char *cd_buf; /* Buffer for output. */ 1738dffb485Schristos int cd_err; /* Saved error value. */ 1748dffb485Schristos int cd_enomem; /* Nonzero if OOM during printing. */ 1758dffb485Schristos } ctf_decl_t; 1768dffb485Schristos 1778dffb485Schristos typedef struct ctf_dtdef 1788dffb485Schristos { 1798dffb485Schristos ctf_list_t dtd_list; /* List forward/back pointers. */ 1808dffb485Schristos ctf_id_t dtd_type; /* Type identifier for this definition. */ 1818dffb485Schristos ctf_type_t dtd_data; /* Type node, including name. */ 1824b169a6bSchristos size_t dtd_vlen_alloc; /* Total vlen space allocated. */ 1834b169a6bSchristos unsigned char *dtd_vlen; /* Variable-length data for this type. */ 1848dffb485Schristos } ctf_dtdef_t; 1858dffb485Schristos 1868dffb485Schristos typedef struct ctf_dvdef 1878dffb485Schristos { 1888dffb485Schristos ctf_list_t dvd_list; /* List forward/back pointers. */ 1898dffb485Schristos char *dvd_name; /* Name associated with variable. */ 1908dffb485Schristos ctf_id_t dvd_type; /* Type of variable. */ 1918dffb485Schristos unsigned long dvd_snapshots; /* Snapshot count when inserted. */ 1928dffb485Schristos } ctf_dvdef_t; 1938dffb485Schristos 1948dffb485Schristos typedef struct ctf_err_warning 1958dffb485Schristos { 1968dffb485Schristos ctf_list_t cew_list; /* List forward/back pointers. */ 1978dffb485Schristos int cew_is_warning; /* 1 if warning, 0 if error. */ 1988dffb485Schristos char *cew_text; /* Error/warning text. */ 1998dffb485Schristos } ctf_err_warning_t; 2008dffb485Schristos 2018dffb485Schristos /* Atoms associate strings with a list of the CTF items that reference that 202*c9055873Schristos string, so that ctf_serialize() can instantiate all the strings using the 2038dffb485Schristos ctf_str_atoms and then reassociate them with the real string later. 2048dffb485Schristos 2058dffb485Schristos Strings can be interned into ctf_str_atom without having refs associated 2068dffb485Schristos with them, for values that are returned to callers, etc. Items are only 207*c9055873Schristos removed from this table on ctf_close(), but on every ctf_serialize(), all 208*c9055873Schristos the csa_refs in all entries are purged. */ 209*c9055873Schristos 210*c9055873Schristos #define CTF_STR_ATOM_FREEABLE 0x1 211*c9055873Schristos #define CTF_STR_ATOM_MOVABLE 0x2 2128dffb485Schristos 2138dffb485Schristos typedef struct ctf_str_atom 2148dffb485Schristos { 215*c9055873Schristos char *csa_str; /* Pointer to string (also used as hash key). */ 2168dffb485Schristos ctf_list_t csa_refs; /* This string's refs. */ 2178dffb485Schristos uint32_t csa_offset; /* Strtab offset, if any. */ 2188dffb485Schristos uint32_t csa_external_offset; /* External strtab offset, if any. */ 2198dffb485Schristos unsigned long csa_snapshot_id; /* Snapshot ID at time of creation. */ 220*c9055873Schristos int csa_flags; /* CTF_STR_ATOM_* flags. */ 2218dffb485Schristos } ctf_str_atom_t; 2228dffb485Schristos 2238dffb485Schristos /* The refs of a single string in the atoms table. */ 2248dffb485Schristos 2258dffb485Schristos typedef struct ctf_str_atom_ref 2268dffb485Schristos { 2278dffb485Schristos ctf_list_t caf_list; /* List forward/back pointers. */ 2288dffb485Schristos uint32_t *caf_ref; /* A single ref to this string. */ 2298dffb485Schristos } ctf_str_atom_ref_t; 2308dffb485Schristos 231*c9055873Schristos /* Like a ctf_str_atom_ref_t, but specific to movable refs. */ 232*c9055873Schristos 233*c9055873Schristos typedef struct ctf_str_atom_ref_movable 234*c9055873Schristos { 235*c9055873Schristos ctf_list_t caf_list; /* List forward/back pointers. */ 236*c9055873Schristos uint32_t *caf_ref; /* A single ref to this string. */ 237*c9055873Schristos ctf_dynhash_t *caf_movable_refs; /* Backpointer to ctf_str_movable_refs for this dict. */ 238*c9055873Schristos } ctf_str_atom_ref_movable_t; 239*c9055873Schristos 2404b169a6bSchristos /* A single linker-provided symbol, during symbol addition, possibly before we 2414b169a6bSchristos have been given external strtab refs. */ 2424b169a6bSchristos typedef struct ctf_in_flight_dynsym 2434b169a6bSchristos { 2444b169a6bSchristos ctf_list_t cid_list; /* List forward/back pointers. */ 2454b169a6bSchristos ctf_link_sym_t cid_sym; /* The linker-known symbol. */ 2464b169a6bSchristos } ctf_in_flight_dynsym_t; 2474b169a6bSchristos 2488dffb485Schristos /* The structure used as the key in a ctf_link_type_mapping. The value is a 2498dffb485Schristos type index, not a type ID. */ 2508dffb485Schristos 2518dffb485Schristos typedef struct ctf_link_type_key 2528dffb485Schristos { 2534b169a6bSchristos ctf_dict_t *cltk_fp; 2548dffb485Schristos ctf_id_t cltk_idx; 2558dffb485Schristos } ctf_link_type_key_t; 2568dffb485Schristos 2574b169a6bSchristos /* The structure used as the key in a cd_id_to_dict_t on 32-bit platforms. */ 2588dffb485Schristos typedef struct ctf_type_id_key 2598dffb485Schristos { 2608dffb485Schristos int ctii_input_num; 2618dffb485Schristos ctf_id_t ctii_type; 2628dffb485Schristos } ctf_type_id_key_t; 2638dffb485Schristos 2648dffb485Schristos /* Deduplicator state. 2658dffb485Schristos 2668dffb485Schristos The dedup state below uses three terms consistently. A "hash" is a 2678dffb485Schristos ctf_dynhash_t; a "hash value" is the hash value of a type as returned by 2688dffb485Schristos ctf_dedup_hash_type; a "global type ID" or "global ID" is a packed-together 2694b169a6bSchristos reference to a single ctf_dict_t (by array index in an array of inputs) and 2708dffb485Schristos ctf_id_t, i.e. a single instance of some hash value in some input. 2718dffb485Schristos 2728dffb485Schristos The deduplication algorithm takes a bunch of inputs and yields a single 2738dffb485Schristos shared "output" and possibly many outputs corresponding to individual inputs 2748dffb485Schristos that still contain types after sharing of unconflicted types. Almost all 2758dffb485Schristos deduplicator state is stored in the struct ctf_dedup in the output, though a 2768dffb485Schristos (very) few things are stored in inputs for simplicity's sake, usually if they 2778dffb485Schristos are linking together things within the scope of a single TU. 2788dffb485Schristos 2798dffb485Schristos Flushed at the end of every ctf_dedup run. */ 2808dffb485Schristos 2818dffb485Schristos typedef struct ctf_dedup 2828dffb485Schristos { 2838dffb485Schristos /* The CTF linker flags in force for this dedup run. */ 2848dffb485Schristos int cd_link_flags; 2858dffb485Schristos 2868dffb485Schristos /* On 32-bit platforms only, a hash of global type IDs, in the form of 2878dffb485Schristos a ctf_link_type_id_key_t. */ 2884b169a6bSchristos ctf_dynhash_t *cd_id_to_dict_t; 2898dffb485Schristos 2908dffb485Schristos /* Atoms tables of decorated names: maps undecorated name to decorated name. 2914b169a6bSchristos (The actual allocations are in the CTF dict for the former and the real 2928dffb485Schristos atoms table for the latter). Uses the same namespaces as ctf_lookups, 2938dffb485Schristos below, but has no need for null-termination. */ 2948dffb485Schristos ctf_dynhash_t *cd_decorated_names[4]; 2958dffb485Schristos 2968dffb485Schristos /* Map type names to a hash from type hash value -> number of times each value 2978dffb485Schristos has appeared. */ 2988dffb485Schristos ctf_dynhash_t *cd_name_counts; 2998dffb485Schristos 3008dffb485Schristos /* Map global type IDs to type hash values. Used to determine if types are 3018dffb485Schristos already hashed without having to recompute their hash values again, and to 3028dffb485Schristos link types together at later stages. Forwards that are peeked through to 3038dffb485Schristos structs and unions are not represented in here, so lookups that might be 3048dffb485Schristos such a type (in practice, all lookups) must go via cd_replaced_types first 3058dffb485Schristos to take this into account. Discarded before each rehashing. */ 3068dffb485Schristos ctf_dynhash_t *cd_type_hashes; 3078dffb485Schristos 3088dffb485Schristos /* Maps from the names of structs/unions/enums to a a single GID which is the 3098dffb485Schristos only appearance of that type in any input: if it appears in more than one 3108dffb485Schristos input, a value which is a GID with an input_num of -1 appears. Used in 3118dffb485Schristos share-duplicated link mode link modes to determine whether structs/unions 3128dffb485Schristos can be cited from multiple TUs. Only populated in that link mode. */ 3138dffb485Schristos ctf_dynhash_t *cd_struct_origin; 3148dffb485Schristos 3158dffb485Schristos /* Maps type hash values to a set of hash values of the types that cite them: 3168dffb485Schristos i.e., pointing backwards up the type graph. Used for recursive conflict 3178dffb485Schristos marking. Citations from tagged structures, unions, and forwards do not 3188dffb485Schristos appear in this graph. */ 3198dffb485Schristos ctf_dynhash_t *cd_citers; 3208dffb485Schristos 3218dffb485Schristos /* Maps type hash values to input global type IDs. The value is a set (a 3228dffb485Schristos hash) of global type IDs. Discarded before each rehashing. The result of 3238dffb485Schristos the ctf_dedup function. */ 3248dffb485Schristos ctf_dynhash_t *cd_output_mapping; 3258dffb485Schristos 3268dffb485Schristos /* A map giving the GID of the first appearance of each type for each type 3278dffb485Schristos hash value. */ 3288dffb485Schristos ctf_dynhash_t *cd_output_first_gid; 3298dffb485Schristos 3308dffb485Schristos /* Used to ensure that we never try to map a single type ID to more than one 3318dffb485Schristos hash. */ 3328dffb485Schristos ctf_dynhash_t *cd_output_mapping_guard; 3338dffb485Schristos 3348dffb485Schristos /* Maps the global type IDs of structures in input TUs whose members still 3358dffb485Schristos need emission to the global type ID of the already-emitted target type 3368dffb485Schristos (which has no members yet) in the appropriate target. Uniquely, the latter 3378dffb485Schristos ID represents a *target* ID (i.e. the cd_output_mapping of some specified 3388dffb485Schristos input): we encode the shared (parent) dict with an ID of -1. */ 3398dffb485Schristos ctf_dynhash_t *cd_emission_struct_members; 3408dffb485Schristos 3418dffb485Schristos /* A set (a hash) of hash values of conflicting types. */ 3428dffb485Schristos ctf_dynset_t *cd_conflicting_types; 3438dffb485Schristos 3444b169a6bSchristos /* A hash mapping fp *'s of inputs to their input_nums. Used only by 3454b169a6bSchristos functions outside the core ctf_dedup / ctf_dedup_emit machinery which do 3464b169a6bSchristos not take an inputs array. */ 3474b169a6bSchristos ctf_dynhash_t *cd_input_nums; 3484b169a6bSchristos 3498dffb485Schristos /* Maps type hashes to ctf_id_t's in this dictionary. Populated only at 3508dffb485Schristos emission time, in the dictionary where emission is taking place. */ 3518dffb485Schristos ctf_dynhash_t *cd_output_emission_hashes; 3528dffb485Schristos 3538dffb485Schristos /* Maps the decorated names of conflicted cross-TU forwards that were forcibly 3548dffb485Schristos emitted in this TU to their emitted ctf_id_ts. Populated only at emission 3558dffb485Schristos time, in the dictionary where emission is taking place. */ 3568dffb485Schristos ctf_dynhash_t *cd_output_emission_conflicted_forwards; 3578dffb485Schristos 3588dffb485Schristos /* Points to the output counterpart of this input dictionary, at emission 3598dffb485Schristos time. */ 3604b169a6bSchristos ctf_dict_t *cd_output; 3618dffb485Schristos } ctf_dedup_t; 3628dffb485Schristos 3634b169a6bSchristos /* The ctf_dict is the structure used to represent a CTF dictionary to library 3648dffb485Schristos clients, who see it only as an opaque pointer. Modifications can therefore 3658dffb485Schristos be made freely to this structure without regard to client versioning. The 3664b169a6bSchristos ctf_dict_t typedef appears in <ctf-api.h> and declares a forward tag. 367*c9055873Schristos (A ctf_file_t typedef also appears there, for historical reasons.) */ 3688dffb485Schristos 3694b169a6bSchristos struct ctf_dict 3708dffb485Schristos { 3714b169a6bSchristos const ctf_dictops_t *ctf_dictops; /* Version-specific dict operations. */ 3724b169a6bSchristos struct ctf_header *ctf_header; /* The header from this CTF dict. */ 3734b169a6bSchristos unsigned char ctf_openflags; /* Flags the dict had when opened. */ 3748dffb485Schristos ctf_sect_t ctf_data; /* CTF data from object file. */ 375*c9055873Schristos ctf_sect_t ctf_ext_symtab; /* Symbol table from object file. */ 376*c9055873Schristos ctf_sect_t ctf_ext_strtab; /* String table from object file. */ 377*c9055873Schristos int ctf_symsect_little_endian; /* Endianness of the ctf_ext_symtab. */ 378*c9055873Schristos ctf_dynhash_t *ctf_symhash_func; /* (partial) hash, symsect name -> idx. */ 379*c9055873Schristos ctf_dynhash_t *ctf_symhash_objt; /* ditto, for object symbols. */ 3804b169a6bSchristos size_t ctf_symhash_latest; /* Amount of symsect scanned so far. */ 3818dffb485Schristos ctf_dynhash_t *ctf_prov_strtab; /* Maps provisional-strtab offsets 3828dffb485Schristos to names. */ 3838dffb485Schristos ctf_dynhash_t *ctf_syn_ext_strtab; /* Maps ext-strtab offsets to names. */ 3848dffb485Schristos void *ctf_data_mmapped; /* CTF data we mmapped, to free later. */ 3858dffb485Schristos size_t ctf_data_mmapped_len; /* Length of CTF data we mmapped. */ 386*c9055873Schristos ctf_dynhash_t *ctf_structs; /* Hash table of struct types. */ 387*c9055873Schristos ctf_dynhash_t *ctf_unions; /* Hash table of union types. */ 388*c9055873Schristos ctf_dynhash_t *ctf_enums; /* Hash table of enum types. */ 389*c9055873Schristos ctf_dynhash_t *ctf_names; /* Hash table of remaining type names. */ 3908dffb485Schristos ctf_lookup_t ctf_lookups[5]; /* Pointers to nametabs for name lookup. */ 3918dffb485Schristos ctf_strs_t ctf_str[2]; /* Array of string table base and bounds. */ 392*c9055873Schristos ctf_strs_writable_t *ctf_dynstrtab; /* Dynamically allocated string table, if any. */ 3938dffb485Schristos ctf_dynhash_t *ctf_str_atoms; /* Hash table of ctf_str_atoms_t. */ 394*c9055873Schristos ctf_dynhash_t *ctf_str_movable_refs; /* Hash table of void * -> ctf_str_atom_ref_t. */ 3958dffb485Schristos uint32_t ctf_str_prov_offset; /* Latest provisional offset assigned so far. */ 3968dffb485Schristos unsigned char *ctf_base; /* CTF file pointer. */ 3978dffb485Schristos unsigned char *ctf_dynbase; /* Freeable CTF file pointer. */ 3988dffb485Schristos unsigned char *ctf_buf; /* Uncompressed CTF data buffer. */ 3998dffb485Schristos size_t ctf_size; /* Size of CTF header + uncompressed data. */ 4004b169a6bSchristos uint32_t *ctf_sxlate; /* Translation table for unindexed symtypetab 4014b169a6bSchristos entries. */ 4028dffb485Schristos unsigned long ctf_nsyms; /* Number of entries in symtab xlate table. */ 4038dffb485Schristos uint32_t *ctf_txlate; /* Translation table for type IDs. */ 4048dffb485Schristos uint32_t *ctf_ptrtab; /* Translation table for pointer-to lookups. */ 4058dffb485Schristos size_t ctf_ptrtab_len; /* Num types storable in ptrtab currently. */ 4064b169a6bSchristos uint32_t *ctf_pptrtab; /* Parent types pointed to by child dicts. */ 4074b169a6bSchristos size_t ctf_pptrtab_len; /* Num types storable in pptrtab currently. */ 4084b169a6bSchristos uint32_t ctf_pptrtab_typemax; /* Max child type when pptrtab last updated. */ 4094b169a6bSchristos uint32_t *ctf_funcidx_names; /* Name of each function symbol in symtypetab 4104b169a6bSchristos (if indexed). */ 4114b169a6bSchristos uint32_t *ctf_objtidx_names; /* Likewise, for object symbols. */ 4124b169a6bSchristos size_t ctf_nfuncidx; /* Number of funcidx entries. */ 4134b169a6bSchristos uint32_t *ctf_funcidx_sxlate; /* Offsets into funcinfo for a given funcidx. */ 4144b169a6bSchristos uint32_t *ctf_objtidx_sxlate; /* Likewise, for ctf_objtidx. */ 4154b169a6bSchristos size_t ctf_nobjtidx; /* Number of objtidx entries. */ 416*c9055873Schristos ctf_dynhash_t *ctf_objthash; /* Dynamic: name -> type ID. */ 417*c9055873Schristos ctf_dynhash_t *ctf_funchash; /* Dynamic: name -> CTF_K_FUNCTION type ID. */ 4184b169a6bSchristos 4194b169a6bSchristos /* The next three are linker-derived state found in ctf_link targets only. */ 4204b169a6bSchristos 4214b169a6bSchristos ctf_dynhash_t *ctf_dynsyms; /* Symbol info from ctf_link_shuffle_syms. */ 4224b169a6bSchristos ctf_link_sym_t **ctf_dynsymidx; /* Indexes ctf_dynsyms by symidx. */ 4234b169a6bSchristos uint32_t ctf_dynsymmax; /* Maximum ctf_dynsym index. */ 4244b169a6bSchristos ctf_list_t ctf_in_flight_dynsyms; /* Dynsyms during accumulation. */ 4258dffb485Schristos struct ctf_varent *ctf_vars; /* Sorted variable->type mapping. */ 4268dffb485Schristos unsigned long ctf_nvars; /* Number of variables in ctf_vars. */ 4278dffb485Schristos unsigned long ctf_typemax; /* Maximum valid type ID number. */ 428*c9055873Schristos unsigned long ctf_stypes; /* Number of static (non-dynamic) types. */ 4298dffb485Schristos const ctf_dmodel_t *ctf_dmodel; /* Data model pointer (see above). */ 4308dffb485Schristos const char *ctf_cuname; /* Compilation unit name (if any). */ 4318dffb485Schristos char *ctf_dyncuname; /* Dynamically allocated name of CU. */ 4324b169a6bSchristos struct ctf_dict *ctf_parent; /* Parent CTF dict (if any). */ 4338dffb485Schristos int ctf_parent_unreffed; /* Parent set by ctf_import_unref? */ 4344b169a6bSchristos const char *ctf_parlabel; /* Label in parent dict (if any). */ 4358dffb485Schristos const char *ctf_parname; /* Basename of parent (if any). */ 4368dffb485Schristos char *ctf_dynparname; /* Dynamically allocated name of parent. */ 4378dffb485Schristos uint32_t ctf_parmax; /* Highest type ID of a parent type. */ 4388dffb485Schristos uint32_t ctf_refcnt; /* Reference count (for parent links). */ 4398dffb485Schristos uint32_t ctf_flags; /* Libctf flags (see below). */ 4408dffb485Schristos int ctf_errno; /* Error code for most recent error. */ 4418dffb485Schristos int ctf_version; /* CTF data version. */ 4428dffb485Schristos ctf_dynhash_t *ctf_dthash; /* Hash of dynamic type definitions. */ 4438dffb485Schristos ctf_list_t ctf_dtdefs; /* List of dynamic type definitions. */ 4448dffb485Schristos ctf_dynhash_t *ctf_dvhash; /* Hash of dynamic variable mappings. */ 4458dffb485Schristos ctf_list_t ctf_dvdefs; /* List of dynamic variable definitions. */ 4468dffb485Schristos unsigned long ctf_dtoldid; /* Oldest id that has been committed. */ 4478dffb485Schristos unsigned long ctf_snapshots; /* ctf_snapshot() plus ctf_update() count. */ 4488dffb485Schristos unsigned long ctf_snapshot_lu; /* ctf_snapshot() call count at last update. */ 4494b169a6bSchristos ctf_archive_t *ctf_archive; /* Archive this ctf_dict_t came from. */ 4508dffb485Schristos ctf_list_t ctf_errs_warnings; /* CTF errors and warnings. */ 4518dffb485Schristos ctf_dynhash_t *ctf_link_inputs; /* Inputs to this link. */ 4528dffb485Schristos ctf_dynhash_t *ctf_link_outputs; /* Additional outputs from this link. */ 4538dffb485Schristos 4544b169a6bSchristos /* If a link input CU, points at the corresponding per-CU output (if any); 4554b169a6bSchristos if an output, points at the input (if any). */ 4564b169a6bSchristos ctf_dict_t *ctf_link_in_out; 4574b169a6bSchristos 4584b169a6bSchristos /* Map input types to output types for ctf_add_type. Key is a 4594b169a6bSchristos ctf_link_type_key_t: value is a type ID. */ 4608dffb485Schristos ctf_dynhash_t *ctf_link_type_mapping; 4618dffb485Schristos 4628dffb485Schristos /* Map input CU names to output CTF dict names: populated in the top-level 4638dffb485Schristos output dict. 4648dffb485Schristos 4658dffb485Schristos Key and value are dynamically-allocated strings. */ 4668dffb485Schristos ctf_dynhash_t *ctf_link_in_cu_mapping; 4678dffb485Schristos 4688dffb485Schristos /* Map output CTF dict names to input CU names: populated in the top-level 4698dffb485Schristos output dict. A hash of string to hash (set) of strings. Key and 4708dffb485Schristos individual value members are shared with ctf_link_in_cu_mapping. */ 4718dffb485Schristos ctf_dynhash_t *ctf_link_out_cu_mapping; 4728dffb485Schristos 4734b169a6bSchristos /* CTF linker flags. Set on the parent output dict (the one passed to 4744b169a6bSchristos ctf_link). Only respected when LCTF_LINKING set in ctf_flags. */ 4758dffb485Schristos int ctf_link_flags; 4768dffb485Schristos 4778dffb485Schristos /* Allow the caller to change the name of link archive members. */ 4788dffb485Schristos ctf_link_memb_name_changer_f *ctf_link_memb_name_changer; 4798dffb485Schristos void *ctf_link_memb_name_changer_arg; /* Argument for it. */ 4808dffb485Schristos 4818dffb485Schristos /* Allow the caller to filter out variables they don't care about. */ 4828dffb485Schristos ctf_link_variable_filter_f *ctf_link_variable_filter; 4838dffb485Schristos void *ctf_link_variable_filter_arg; /* Argument for it. */ 4848dffb485Schristos 4858dffb485Schristos ctf_dynhash_t *ctf_add_processing; /* Types ctf_add_type is working on now. */ 4868dffb485Schristos 4878dffb485Schristos /* Atoms table for dedup string storage. All strings in the ctf_dedup_t are 4888dffb485Schristos stored here. Only the _alloc copy is allocated or freed: the 4898dffb485Schristos ctf_dedup_atoms may be pointed to some other CTF dict, to share its atoms. 4908dffb485Schristos We keep the atoms table outside the ctf_dedup so that atoms can be 4918dffb485Schristos preserved across multiple similar links, such as when doing cu-mapped 4928dffb485Schristos links. */ 4938dffb485Schristos ctf_dynset_t *ctf_dedup_atoms; 4948dffb485Schristos ctf_dynset_t *ctf_dedup_atoms_alloc; 4958dffb485Schristos 4968dffb485Schristos ctf_dedup_t ctf_dedup; /* Deduplicator state. */ 4978dffb485Schristos 4988dffb485Schristos char *ctf_tmp_typeslice; /* Storage for slicing up type names. */ 4998dffb485Schristos size_t ctf_tmp_typeslicelen; /* Size of the typeslice. */ 5008dffb485Schristos void *ctf_specific; /* Data for ctf_get/setspecific(). */ 5018dffb485Schristos }; 5028dffb485Schristos 5034b169a6bSchristos /* An abstraction over both a ctf_dict_t and a ctf_archive_t. */ 5048dffb485Schristos 5058dffb485Schristos struct ctf_archive_internal 5068dffb485Schristos { 5078dffb485Schristos int ctfi_is_archive; 5088dffb485Schristos int ctfi_unmap_on_close; 5094b169a6bSchristos ctf_dict_t *ctfi_dict; 5108dffb485Schristos struct ctf_archive *ctfi_archive; 5114b169a6bSchristos ctf_dynhash_t *ctfi_dicts; /* Dicts we have opened and cached. */ 5124b169a6bSchristos ctf_dict_t *ctfi_crossdict_cache; /* Cross-dict caching. */ 5134b169a6bSchristos ctf_dict_t **ctfi_symdicts; /* Array of index -> ctf_dict_t *. */ 5144b169a6bSchristos ctf_dynhash_t *ctfi_symnamedicts; /* Hash of name -> ctf_dict_t *. */ 5158dffb485Schristos ctf_sect_t ctfi_symsect; 5164b169a6bSchristos int ctfi_symsect_little_endian; /* -1 for unknown / do not set. */ 5178dffb485Schristos ctf_sect_t ctfi_strsect; 5188dffb485Schristos int ctfi_free_symsect; 5198dffb485Schristos int ctfi_free_strsect; 5208dffb485Schristos void *ctfi_data; 5218dffb485Schristos bfd *ctfi_abfd; /* Optional source of section data. */ 5228dffb485Schristos void (*ctfi_bfd_close) (struct ctf_archive_internal *); 5238dffb485Schristos }; 5248dffb485Schristos 5258dffb485Schristos /* Iterator state for the *_next() functions. */ 5268dffb485Schristos 5278dffb485Schristos /* A single hash key/value pair. */ 5288dffb485Schristos typedef struct ctf_next_hkv 5298dffb485Schristos { 5308dffb485Schristos void *hkv_key; 5318dffb485Schristos void *hkv_value; 5328dffb485Schristos } ctf_next_hkv_t; 5338dffb485Schristos 5348dffb485Schristos struct ctf_next 5358dffb485Schristos { 5368dffb485Schristos void (*ctn_iter_fun) (void); 5378dffb485Schristos ctf_id_t ctn_type; 5388dffb485Schristos ssize_t ctn_size; 5398dffb485Schristos ssize_t ctn_increment; 5404b169a6bSchristos const ctf_type_t *ctn_tp; 5418dffb485Schristos uint32_t ctn_n; 5424b169a6bSchristos 5434b169a6bSchristos /* Some iterators contain other iterators, in addition to their other 5444b169a6bSchristos state. */ 5454b169a6bSchristos ctf_next_t *ctn_next; 5464b169a6bSchristos 5474b169a6bSchristos /* We can save space on this side of things by noting that a dictionary is 5488dffb485Schristos either dynamic or not, as a whole, and a given iterator can only iterate 5498dffb485Schristos over one kind of thing at once: so we can overlap the DTD and non-DTD 5508dffb485Schristos members, and the structure, variable and enum members, etc. */ 5518dffb485Schristos union 5528dffb485Schristos { 5534b169a6bSchristos unsigned char *ctn_vlen; 5548dffb485Schristos const ctf_enum_t *ctn_en; 5558dffb485Schristos const ctf_dvdef_t *ctn_dvd; 5568dffb485Schristos ctf_next_hkv_t *ctn_sorted_hkv; 5578dffb485Schristos void **ctn_hash_slot; 5588dffb485Schristos } u; 5594b169a6bSchristos 5604b169a6bSchristos /* This union is of various sorts of dict we can iterate over: 5618dffb485Schristos currently dictionaries and archives, dynhashes, and dynsets. */ 5628dffb485Schristos union 5638dffb485Schristos { 5644b169a6bSchristos const ctf_dict_t *ctn_fp; 5658dffb485Schristos const ctf_archive_t *ctn_arc; 5668dffb485Schristos const ctf_dynhash_t *ctn_h; 5678dffb485Schristos const ctf_dynset_t *ctn_s; 5688dffb485Schristos } cu; 5698dffb485Schristos }; 5708dffb485Schristos 5718dffb485Schristos /* Return x rounded up to an alignment boundary. 5728dffb485Schristos eg, P2ROUNDUP(0x1234, 0x100) == 0x1300 (0x13*align) 5738dffb485Schristos eg, P2ROUNDUP(0x5600, 0x100) == 0x5600 (0x56*align) */ 5748dffb485Schristos #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 5758dffb485Schristos 5768dffb485Schristos /* * If an offs is not aligned already then round it up and align it. */ 5778dffb485Schristos #define LCTF_ALIGN_OFFS(offs, align) ((offs + (align - 1)) & ~(align - 1)) 5788dffb485Schristos 5798dffb485Schristos #define LCTF_TYPE_ISPARENT(fp, id) ((id) <= fp->ctf_parmax) 5808dffb485Schristos #define LCTF_TYPE_ISCHILD(fp, id) ((id) > fp->ctf_parmax) 5818dffb485Schristos #define LCTF_TYPE_TO_INDEX(fp, id) ((id) & (fp->ctf_parmax)) 5828dffb485Schristos #define LCTF_INDEX_TO_TYPE(fp, id, child) (child ? ((id) | (fp->ctf_parmax+1)) : \ 5838dffb485Schristos (id)) 5848dffb485Schristos 5858dffb485Schristos #define LCTF_INDEX_TO_TYPEPTR(fp, i) \ 586*c9055873Schristos ((i > fp->ctf_stypes) ? \ 5878dffb485Schristos &(ctf_dtd_lookup (fp, LCTF_INDEX_TO_TYPE \ 5888dffb485Schristos (fp, i, fp->ctf_flags & LCTF_CHILD))->dtd_data) : \ 5898dffb485Schristos (ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)])) 5908dffb485Schristos 5914b169a6bSchristos #define LCTF_INFO_KIND(fp, info) ((fp)->ctf_dictops->ctfo_get_kind(info)) 5924b169a6bSchristos #define LCTF_INFO_ISROOT(fp, info) ((fp)->ctf_dictops->ctfo_get_root(info)) 5934b169a6bSchristos #define LCTF_INFO_VLEN(fp, info) ((fp)->ctf_dictops->ctfo_get_vlen(info)) 5948dffb485Schristos #define LCTF_VBYTES(fp, kind, size, vlen) \ 5954b169a6bSchristos ((fp)->ctf_dictops->ctfo_get_vbytes(fp, kind, size, vlen)) 5968dffb485Schristos 5974b169a6bSchristos #define LCTF_CHILD 0x0001 /* CTF dict is a child. */ 598*c9055873Schristos #define LCTF_LINKING 0x0002 /* CTF link is underway: respect ctf_link_flags. */ 5998dffb485Schristos 600*c9055873Schristos extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, int); 6014b169a6bSchristos extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t); 602*c9055873Schristos extern ctf_id_t ctf_lookup_variable_here (ctf_dict_t *fp, const char *name); 603*c9055873Schristos extern ctf_id_t ctf_lookup_by_sym_or_name (ctf_dict_t *, unsigned long symidx, 604*c9055873Schristos const char *symname, int try_parent, 605*c9055873Schristos int is_function); 6064b169a6bSchristos extern ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *, int, const char *); 6074b169a6bSchristos extern void ctf_set_ctl_hashes (ctf_dict_t *); 608*c9055873Schristos extern ctf_id_t ctf_symbol_next_static (ctf_dict_t *, ctf_next_t **, 609*c9055873Schristos const char **, int); 6108dffb485Schristos 6114b169a6bSchristos extern int ctf_symtab_skippable (ctf_link_sym_t *sym); 6124b169a6bSchristos extern int ctf_add_funcobjt_sym (ctf_dict_t *, int is_function, 6134b169a6bSchristos const char *, ctf_id_t); 6144b169a6bSchristos 6154b169a6bSchristos extern ctf_dict_t *ctf_get_dict (ctf_dict_t *fp, ctf_id_t type); 6168dffb485Schristos 6178dffb485Schristos typedef unsigned int (*ctf_hash_fun) (const void *ptr); 6188dffb485Schristos extern unsigned int ctf_hash_integer (const void *ptr); 6198dffb485Schristos extern unsigned int ctf_hash_string (const void *ptr); 6208dffb485Schristos extern unsigned int ctf_hash_type_key (const void *ptr); 6218dffb485Schristos extern unsigned int ctf_hash_type_id_key (const void *ptr); 6228dffb485Schristos 6238dffb485Schristos typedef int (*ctf_hash_eq_fun) (const void *, const void *); 6248dffb485Schristos extern int ctf_hash_eq_integer (const void *, const void *); 6258dffb485Schristos extern int ctf_hash_eq_string (const void *, const void *); 6268dffb485Schristos extern int ctf_hash_eq_type_key (const void *, const void *); 6278dffb485Schristos extern int ctf_hash_eq_type_id_key (const void *, const void *); 6288dffb485Schristos 6298dffb485Schristos typedef void (*ctf_hash_free_fun) (void *); 6308dffb485Schristos 6318dffb485Schristos typedef void (*ctf_hash_iter_f) (void *key, void *value, void *arg); 6328dffb485Schristos typedef int (*ctf_hash_iter_remove_f) (void *key, void *value, void *arg); 6338dffb485Schristos typedef int (*ctf_hash_iter_find_f) (void *key, void *value, void *arg); 6348dffb485Schristos typedef int (*ctf_hash_sort_f) (const ctf_next_hkv_t *, const ctf_next_hkv_t *, 6358dffb485Schristos void *arg); 6368dffb485Schristos 6378dffb485Schristos extern ctf_dynhash_t *ctf_dynhash_create (ctf_hash_fun, ctf_hash_eq_fun, 6388dffb485Schristos ctf_hash_free_fun, ctf_hash_free_fun); 639*c9055873Schristos extern ctf_dynhash_t *ctf_dynhash_create_sized (unsigned long, ctf_hash_fun, 640*c9055873Schristos ctf_hash_eq_fun, 641*c9055873Schristos ctf_hash_free_fun, 642*c9055873Schristos ctf_hash_free_fun); 643*c9055873Schristos 6448dffb485Schristos extern int ctf_dynhash_insert (ctf_dynhash_t *, void *, void *); 6458dffb485Schristos extern void ctf_dynhash_remove (ctf_dynhash_t *, const void *); 6468dffb485Schristos extern size_t ctf_dynhash_elements (ctf_dynhash_t *); 6478dffb485Schristos extern void ctf_dynhash_empty (ctf_dynhash_t *); 648*c9055873Schristos extern int ctf_dynhash_insert_type (ctf_dict_t *, ctf_dynhash_t *, uint32_t, uint32_t); 649*c9055873Schristos extern ctf_id_t ctf_dynhash_lookup_type (ctf_dynhash_t *, const char *); 6508dffb485Schristos extern void *ctf_dynhash_lookup (ctf_dynhash_t *, const void *); 6518dffb485Schristos extern int ctf_dynhash_lookup_kv (ctf_dynhash_t *, const void *key, 6528dffb485Schristos const void **orig_key, void **value); 6538dffb485Schristos extern void ctf_dynhash_destroy (ctf_dynhash_t *); 6548dffb485Schristos extern void ctf_dynhash_iter (ctf_dynhash_t *, ctf_hash_iter_f, void *); 6558dffb485Schristos extern void ctf_dynhash_iter_remove (ctf_dynhash_t *, ctf_hash_iter_remove_f, 6568dffb485Schristos void *); 6578dffb485Schristos extern void *ctf_dynhash_iter_find (ctf_dynhash_t *, ctf_hash_iter_find_f, 6588dffb485Schristos void *); 6594b169a6bSchristos extern int ctf_dynhash_sort_by_name (const ctf_next_hkv_t *, 6604b169a6bSchristos const ctf_next_hkv_t *, 6614b169a6bSchristos void * _libctf_unused_); 6628dffb485Schristos extern int ctf_dynhash_next (ctf_dynhash_t *, ctf_next_t **, 6638dffb485Schristos void **key, void **value); 6648dffb485Schristos extern int ctf_dynhash_next_sorted (ctf_dynhash_t *, ctf_next_t **, 6658dffb485Schristos void **key, void **value, ctf_hash_sort_f, 6668dffb485Schristos void *); 6678dffb485Schristos 6688dffb485Schristos extern ctf_dynset_t *ctf_dynset_create (htab_hash, htab_eq, ctf_hash_free_fun); 6698dffb485Schristos extern int ctf_dynset_insert (ctf_dynset_t *, void *); 6708dffb485Schristos extern void ctf_dynset_remove (ctf_dynset_t *, const void *); 6718dffb485Schristos extern void ctf_dynset_destroy (ctf_dynset_t *); 6728dffb485Schristos extern void *ctf_dynset_lookup (ctf_dynset_t *, const void *); 6738dffb485Schristos extern int ctf_dynset_exists (ctf_dynset_t *, const void *key, 6748dffb485Schristos const void **orig_key); 6758dffb485Schristos extern int ctf_dynset_next (ctf_dynset_t *, ctf_next_t **, void **key); 6768dffb485Schristos extern void *ctf_dynset_lookup_any (ctf_dynset_t *); 6778dffb485Schristos 6788dffb485Schristos extern void ctf_sha1_init (ctf_sha1_t *); 6798dffb485Schristos extern void ctf_sha1_add (ctf_sha1_t *, const void *, size_t); 6808dffb485Schristos extern char *ctf_sha1_fini (ctf_sha1_t *, char *); 6818dffb485Schristos 6828dffb485Schristos #define ctf_list_prev(elem) ((void *)(((ctf_list_t *)(elem))->l_prev)) 6838dffb485Schristos #define ctf_list_next(elem) ((void *)(((ctf_list_t *)(elem))->l_next)) 6848dffb485Schristos 6858dffb485Schristos extern void ctf_list_append (ctf_list_t *, void *); 6868dffb485Schristos extern void ctf_list_prepend (ctf_list_t *, void *); 6878dffb485Schristos extern void ctf_list_delete (ctf_list_t *, void *); 6888dffb485Schristos extern void ctf_list_splice (ctf_list_t *, ctf_list_t *); 6898dffb485Schristos extern int ctf_list_empty_p (ctf_list_t *lp); 6908dffb485Schristos 6914b169a6bSchristos extern int ctf_dtd_insert (ctf_dict_t *, ctf_dtdef_t *, int flag, int kind); 6924b169a6bSchristos extern void ctf_dtd_delete (ctf_dict_t *, ctf_dtdef_t *); 6934b169a6bSchristos extern ctf_dtdef_t *ctf_dtd_lookup (const ctf_dict_t *, ctf_id_t); 6944b169a6bSchristos extern ctf_dtdef_t *ctf_dynamic_type (const ctf_dict_t *, ctf_id_t); 6958dffb485Schristos 6964b169a6bSchristos extern int ctf_dvd_insert (ctf_dict_t *, ctf_dvdef_t *); 6974b169a6bSchristos extern void ctf_dvd_delete (ctf_dict_t *, ctf_dvdef_t *); 6984b169a6bSchristos extern ctf_dvdef_t *ctf_dvd_lookup (const ctf_dict_t *, const char *); 6998dffb485Schristos 7004b169a6bSchristos extern ctf_id_t ctf_add_encoded (ctf_dict_t *, uint32_t, const char *, 7018dffb485Schristos const ctf_encoding_t *, uint32_t kind); 7024b169a6bSchristos extern ctf_id_t ctf_add_reftype (ctf_dict_t *, uint32_t, ctf_id_t, 7038dffb485Schristos uint32_t kind); 704*c9055873Schristos extern int ctf_add_variable_forced (ctf_dict_t *, const char *, ctf_id_t); 705*c9055873Schristos extern int ctf_add_funcobjt_sym_forced (ctf_dict_t *, int is_function, 706*c9055873Schristos const char *, ctf_id_t); 7078dffb485Schristos 7084b169a6bSchristos extern int ctf_dedup_atoms_init (ctf_dict_t *); 7094b169a6bSchristos extern int ctf_dedup (ctf_dict_t *, ctf_dict_t **, uint32_t ninputs, 7108dffb485Schristos uint32_t *parents, int cu_mapped); 7114b169a6bSchristos extern void ctf_dedup_fini (ctf_dict_t *, ctf_dict_t **, uint32_t); 7124b169a6bSchristos extern ctf_dict_t **ctf_dedup_emit (ctf_dict_t *, ctf_dict_t **, 7138dffb485Schristos uint32_t ninputs, uint32_t *parents, 7148dffb485Schristos uint32_t *noutputs, int cu_mapped); 7154b169a6bSchristos extern ctf_id_t ctf_dedup_type_mapping (ctf_dict_t *fp, ctf_dict_t *src_fp, 7164b169a6bSchristos ctf_id_t src_type); 7178dffb485Schristos 7188dffb485Schristos extern void ctf_decl_init (ctf_decl_t *); 7198dffb485Schristos extern void ctf_decl_fini (ctf_decl_t *); 7204b169a6bSchristos extern void ctf_decl_push (ctf_decl_t *, ctf_dict_t *, ctf_id_t); 7218dffb485Schristos 7228dffb485Schristos _libctf_printflike_ (2, 3) 7238dffb485Schristos extern void ctf_decl_sprintf (ctf_decl_t *, const char *, ...); 7248dffb485Schristos extern char *ctf_decl_buf (ctf_decl_t *cd); 7258dffb485Schristos 7264b169a6bSchristos extern const char *ctf_strptr (ctf_dict_t *, uint32_t); 7274b169a6bSchristos extern const char *ctf_strraw (ctf_dict_t *, uint32_t); 7284b169a6bSchristos extern const char *ctf_strraw_explicit (ctf_dict_t *, uint32_t, 7298dffb485Schristos ctf_strs_t *); 730*c9055873Schristos extern const char *ctf_strptr_validate (ctf_dict_t *, uint32_t); 7314b169a6bSchristos extern int ctf_str_create_atoms (ctf_dict_t *); 7324b169a6bSchristos extern void ctf_str_free_atoms (ctf_dict_t *); 7334b169a6bSchristos extern uint32_t ctf_str_add (ctf_dict_t *, const char *); 7344b169a6bSchristos extern uint32_t ctf_str_add_ref (ctf_dict_t *, const char *, uint32_t *ref); 735*c9055873Schristos extern uint32_t ctf_str_add_movable_ref (ctf_dict_t *, const char *, 736*c9055873Schristos uint32_t *ref); 737*c9055873Schristos extern int ctf_str_move_refs (ctf_dict_t *fp, void *src, size_t len, void *dest); 7384b169a6bSchristos extern int ctf_str_add_external (ctf_dict_t *, const char *, uint32_t offset); 7394b169a6bSchristos extern void ctf_str_remove_ref (ctf_dict_t *, const char *, uint32_t *ref); 7404b169a6bSchristos extern void ctf_str_rollback (ctf_dict_t *, ctf_snapshot_id_t); 7414b169a6bSchristos extern void ctf_str_purge_refs (ctf_dict_t *); 742*c9055873Schristos extern const ctf_strs_writable_t *ctf_str_write_strtab (ctf_dict_t *); 7438dffb485Schristos 7448dffb485Schristos extern struct ctf_archive_internal * 7458dffb485Schristos ctf_new_archive_internal (int is_archive, int unmap_on_close, 7464b169a6bSchristos struct ctf_archive *, ctf_dict_t *, 7478dffb485Schristos const ctf_sect_t *symsect, 7488dffb485Schristos const ctf_sect_t *strsect, int *errp); 7498dffb485Schristos extern struct ctf_archive *ctf_arc_open_internal (const char *, int *); 7508dffb485Schristos extern void ctf_arc_close_internal (struct ctf_archive *); 7514b169a6bSchristos extern const ctf_preamble_t *ctf_arc_bufpreamble (const ctf_sect_t *); 7528dffb485Schristos extern void *ctf_set_open_errno (int *, int); 7534b169a6bSchristos extern void ctf_flip_header (ctf_header_t *); 7544b169a6bSchristos extern int ctf_flip (ctf_dict_t *, ctf_header_t *, unsigned char *, int); 7558dffb485Schristos 7564b169a6bSchristos extern int ctf_import_unref (ctf_dict_t *fp, ctf_dict_t *pfp); 7578dffb485Schristos 7588dffb485Schristos _libctf_malloc_ 7598dffb485Schristos extern void *ctf_mmap (size_t length, size_t offset, int fd); 7608dffb485Schristos extern void ctf_munmap (void *, size_t); 7618dffb485Schristos extern ssize_t ctf_pread (int fd, void *buf, ssize_t count, off_t offset); 7628dffb485Schristos 7638dffb485Schristos extern char *ctf_str_append (char *, const char *); 7648dffb485Schristos extern char *ctf_str_append_noerr (char *, const char *); 7658dffb485Schristos 7664b169a6bSchristos extern ctf_id_t ctf_type_resolve_unsliced (ctf_dict_t *, ctf_id_t); 7674b169a6bSchristos extern int ctf_type_kind_unsliced (ctf_dict_t *, ctf_id_t); 7688dffb485Schristos 7698dffb485Schristos _libctf_printflike_ (1, 2) 7708dffb485Schristos extern void ctf_dprintf (const char *, ...); 7718dffb485Schristos extern void libctf_init_debug (void); 7728dffb485Schristos 7738dffb485Schristos _libctf_printflike_ (4, 5) 7744b169a6bSchristos extern void ctf_err_warn (ctf_dict_t *, int is_warning, int err, 7758dffb485Schristos const char *, ...); 7764b169a6bSchristos extern void ctf_err_warn_to_open (ctf_dict_t *); 7774b169a6bSchristos extern void ctf_assert_fail_internal (ctf_dict_t *, const char *, 7788dffb485Schristos size_t, const char *); 7794b169a6bSchristos extern const char *ctf_link_input_name (ctf_dict_t *); 7808dffb485Schristos 7814b169a6bSchristos extern ctf_link_sym_t *ctf_elf32_to_link_sym (ctf_dict_t *fp, ctf_link_sym_t *dst, 7824b169a6bSchristos const Elf32_Sym *src, uint32_t symidx); 7834b169a6bSchristos extern ctf_link_sym_t *ctf_elf64_to_link_sym (ctf_dict_t *fp, ctf_link_sym_t *dst, 7844b169a6bSchristos const Elf64_Sym *src, uint32_t symidx); 7858dffb485Schristos 7868dffb485Schristos /* Variables, all underscore-prepended. */ 7878dffb485Schristos 7888dffb485Schristos extern const char _CTF_SECTION[]; /* name of CTF ELF section */ 7898dffb485Schristos extern const char _CTF_NULLSTR[]; /* empty string */ 7908dffb485Schristos 7918dffb485Schristos extern int _libctf_version; /* library client version */ 7928dffb485Schristos extern int _libctf_debug; /* debugging messages enabled */ 7938dffb485Schristos 7948dffb485Schristos #include "ctf-inlines.h" 7958dffb485Schristos 7968dffb485Schristos #ifdef __cplusplus 7978dffb485Schristos } 7988dffb485Schristos #endif 7998dffb485Schristos 8008dffb485Schristos #endif /* _CTF_IMPL_H */ 801