objedit.h (1624B)
1 #ifndef KIT_DRIVER_LIB_OBJEDIT_H 2 #define KIT_DRIVER_LIB_OBJEDIT_H 3 4 #include <kit/core.h> 5 #include <kit/object.h> 6 #include <stdint.h> 7 8 #include "driver.h" 9 10 /* Object-editing helpers shared by the `strip` and `objcopy` tools, which both 11 * drop debug sections and then prune symbols not reached by a surviving reloc. 12 * Kept here so the reloc-target scan and the small membership predicates live 13 * in one place rather than being copied between the two drivers. */ 14 15 /* Whether `name` exactly matches one of the `n` NUL-terminated entries in 16 * `list`. An empty `name` never matches. */ 17 int driver_name_in_list(KitSlice name, const char* const* list, uint32_t n); 18 19 /* Whether symbol id `id` appears in `arr[0..n)`. */ 20 int driver_obj_id_in_set(KitObjSymbol id, const KitObjSymbol* arr, uint32_t n); 21 22 /* Collect (deduplicated) the symbol ids targeted by any relocation whose 23 * containing section will survive emit -- relocs hosted in KIT_SEC_DEBUG 24 * sections are skipped, since those sections are about to be dropped and so do 25 * not actually keep their targets alive. Thin wrapper over the libkit 26 * kit_obj_reloc_live_symbols scan: *out owns an exactly-sized array of *n ids, 27 * and *cap is reported equal to *n so the caller's driver_free(*out, 28 * *cap * sizeof(KitObjSymbol)) frees the exact allocation. On failure emits an 29 * error tagged `tool` and returns nonzero. Returns 0 on success. */ 30 int driver_obj_collect_reloc_target_syms(DriverEnv* env, const char* tool, 31 KitObjFile* of, KitObjSymbol** out, 32 uint32_t* n, uint32_t* cap); 33 34 #endif