| Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Interface for libebl. |
| 2 | Copyright (C) 2000, 2001, 2002, 2004, 2005 Red Hat, Inc. |
| 3 | |
| 4 | This program is Open Source software; you can redistribute it and/or |
| 5 | modify it under the terms of the Open Software License version 1.0 as |
| 6 | published by the Open Source Initiative. |
| 7 | |
| 8 | You should have received a copy of the Open Software License along |
| 9 | with this program; if not, you may obtain a copy of the Open Software |
| 10 | License version 1.0 from http://www.opensource.org/licenses/osl.php or |
| 11 | by writing the Open Source Initiative c/o Lawrence Rosen, Esq., |
| 12 | 3001 King Ranch Road, Ukiah, CA 95482. */ |
| 13 | |
| 14 | #ifndef _LIBEBL_H |
| 15 | #define _LIBEBL_H 1 |
| 16 | |
| 17 | #include <gelf.h> |
| 18 | #include <stdbool.h> |
| 19 | #include <stddef.h> |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <elf-knowledge.h> |
| 23 | |
| 24 | |
| 25 | /* Opaque type for the handle. */ |
| 26 | typedef struct ebl Ebl; |
| 27 | |
| 28 | |
| 29 | /* Get backend handle for object associated with ELF handle. */ |
| 30 | extern Ebl *ebl_openbackend (Elf *elf); |
| 31 | /* Similar but without underlying ELF file. */ |
| 32 | extern Ebl *ebl_openbackend_machine (GElf_Half machine); |
| 33 | /* Similar but with emulation name given. */ |
| 34 | extern Ebl *ebl_openbackend_emulation (const char *emulation); |
| 35 | |
| 36 | /* Free resources allocated for backend handle. */ |
| 37 | extern void ebl_closebackend (Ebl *bh); |
| 38 | |
| 39 | |
| 40 | /* Function to call the callback functions including default ELF |
| 41 | handling. */ |
| 42 | |
| 43 | /* Return backend name. */ |
| 44 | extern const char *ebl_backend_name (Ebl *ebl); |
| 45 | |
| 46 | /* Return relocation type name. */ |
| 47 | extern const char *ebl_object_type_name (Ebl *ebl, int object, |
| 48 | char *buf, size_t len); |
| 49 | |
| 50 | /* Return relocation type name. */ |
| 51 | extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc, |
| 52 | char *buf, size_t len); |
| 53 | |
| 54 | /* Check relocation type. */ |
| 55 | extern bool ebl_reloc_type_check (Ebl *ebl, int reloc); |
| 56 | |
| 57 | /* Check relocation type use. */ |
| 58 | extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc); |
| 59 | |
| 60 | /* Check if relocation type is for simple absolute relocations. |
| 61 | Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM. */ |
| 62 | extern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc); |
| 63 | |
| 64 | /* Return true if the symbol type is that referencing the GOT. E.g., |
| 65 | R_386_GOTPC. */ |
| 66 | extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc); |
| 67 | |
| 68 | /* Return segment type name. */ |
| 69 | extern const char *ebl_segment_type_name (Ebl *ebl, int segment, |
| 70 | char *buf, size_t len); |
| 71 | |
| 72 | /* Return section type name. */ |
| 73 | extern const char *ebl_section_type_name (Ebl *ebl, int section, |
| 74 | char *buf, size_t len); |
| 75 | |
| 76 | /* Return section name. */ |
| 77 | extern const char *ebl_section_name (Ebl *ebl, int section, int xsection, |
| 78 | char *buf, size_t len, |
| 79 | const char *scnnames[], size_t shnum); |
| 80 | |
| 81 | /* Return machine flag names. */ |
| 82 | extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags, |
| 83 | char *buf, size_t len); |
| 84 | |
| 85 | /* Check whether machine flag is valid. */ |
| 86 | extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags); |
| 87 | |
| 88 | /* Return symbol type name. */ |
| 89 | extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol, |
| 90 | char *buf, size_t len); |
| 91 | |
| 92 | /* Return symbol binding name. */ |
| 93 | extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding, |
| 94 | char *buf, size_t len); |
| 95 | |
| 96 | /* Return dynamic tag name. */ |
| 97 | extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag, |
| 98 | char *buf, size_t len); |
| 99 | |
| 100 | /* Check dynamic tag. */ |
| 101 | extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag); |
| 102 | |
| 103 | /* Return combined section header flags value. */ |
| 104 | extern GElf_Word ebl_sh_flags_combine (Ebl *ebl, GElf_Word flags1, |
| 105 | GElf_Word flags2); |
| 106 | |
| 107 | /* Return symbolic representation of OS ABI. */ |
| 108 | extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len); |
| 109 | |
| 110 | |
| 111 | /* Return name of the note section type for a core file. */ |
| 112 | extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, |
| 113 | size_t len); |
| 114 | |
| 115 | /* Return name of the note section type for an object file. */ |
| 116 | extern const char *ebl_object_note_type_name (Ebl *ebl, uint32_t type, |
| 117 | char *buf, size_t len); |
| 118 | |
| 119 | /* Print information about core note if available. */ |
| 120 | extern void ebl_core_note (Ebl *ebl, const char *name, uint32_t type, |
| 121 | uint32_t descsz, const char *desc); |
| 122 | |
| 123 | /* Print information about object note if available. */ |
| 124 | extern void ebl_object_note (Ebl *ebl, const char *name, uint32_t type, |
| 125 | uint32_t descsz, const char *desc); |
| 126 | |
| 127 | /* Check section name for being that of a debug informatino section. */ |
| 128 | extern bool ebl_debugscn_p (Ebl *ebl, const char *name); |
| 129 | |
| 130 | /* Check whether given relocation is a copy relocation. */ |
| 131 | extern bool ebl_copy_reloc_p (Ebl *ebl, int reloc); |
| 132 | |
| 133 | |
| 134 | /* CHeck whether section should be stripped. */ |
| 135 | extern bool ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr, |
| 136 | const GElf_Shdr *shdr, const char *name, |
| 137 | bool remove_comment, bool only_remove_debug); |
| 138 | |
| 139 | |
| 140 | /* ELF string table handling. */ |
| 141 | struct Ebl_Strtab; |
| 142 | struct Ebl_Strent; |
| 143 | |
| 144 | /* Create new ELF string table object in memory. */ |
| 145 | extern struct Ebl_Strtab *ebl_strtabinit (bool nullstr); |
| 146 | |
| 147 | /* Free resources allocated for ELF string table ST. */ |
| 148 | extern void ebl_strtabfree (struct Ebl_Strtab *st); |
| 149 | |
| 150 | /* Add string STR (length LEN is != 0) to ELF string table ST. */ |
| 151 | extern struct Ebl_Strent *ebl_strtabadd (struct Ebl_Strtab *st, |
| 152 | const char *str, size_t len); |
| 153 | |
| 154 | /* Finalize string table ST and store size and memory location information |
| 155 | in DATA. */ |
| 156 | extern void ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data); |
| 157 | |
| 158 | /* Get offset in string table for string associated with SE. */ |
| 159 | extern size_t ebl_strtaboffset (struct Ebl_Strent *se); |
| 160 | |
| 161 | /* Return the string associated with SE. */ |
| 162 | extern const char *ebl_string (struct Ebl_Strent *se); |
| 163 | |
| 164 | |
| 165 | /* ELF wide char string table handling. */ |
| 166 | struct Ebl_WStrtab; |
| 167 | struct Ebl_WStrent; |
| 168 | |
| 169 | /* Create new ELF wide char string table object in memory. */ |
| 170 | extern struct Ebl_WStrtab *ebl_wstrtabinit (bool nullstr); |
| 171 | |
| 172 | /* Free resources allocated for ELF wide char string table ST. */ |
| 173 | extern void ebl_wstrtabfree (struct Ebl_WStrtab *st); |
| 174 | |
| 175 | /* Add string STR (length LEN is != 0) to ELF string table ST. */ |
| 176 | extern struct Ebl_WStrent *ebl_wstrtabadd (struct Ebl_WStrtab *st, |
| 177 | const wchar_t *str, size_t len); |
| 178 | |
| 179 | /* Finalize string table ST and store size and memory location information |
| 180 | in DATA. */ |
| 181 | extern void ebl_wstrtabfinalize (struct Ebl_WStrtab *st, Elf_Data *data); |
| 182 | |
| 183 | /* Get offset in wide char string table for string associated with SE. */ |
| 184 | extern size_t ebl_wstrtaboffset (struct Ebl_WStrent *se); |
| 185 | |
| 186 | |
| 187 | /* Generic string table handling. */ |
| 188 | struct Ebl_GStrtab; |
| 189 | struct Ebl_GStrent; |
| 190 | |
| 191 | /* Create new string table object in memory. */ |
| 192 | extern struct Ebl_GStrtab *ebl_gstrtabinit (unsigned int width, bool nullstr); |
| 193 | |
| 194 | /* Free resources allocated for string table ST. */ |
| 195 | extern void ebl_gstrtabfree (struct Ebl_GStrtab *st); |
| 196 | |
| 197 | /* Add string STR (length LEN is != 0) to string table ST. */ |
| 198 | extern struct Ebl_GStrent *ebl_gstrtabadd (struct Ebl_GStrtab *st, |
| 199 | const char *str, size_t len); |
| 200 | |
| 201 | /* Finalize string table ST and store size and memory location information |
| 202 | in DATA. */ |
| 203 | extern void ebl_gstrtabfinalize (struct Ebl_GStrtab *st, Elf_Data *data); |
| 204 | |
| 205 | /* Get offset in wide char string table for string associated with SE. */ |
| 206 | extern size_t ebl_gstrtaboffset (struct Ebl_GStrent *se); |
| 207 | |
| 208 | #endif /* libebl.h */ |