elf.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /*
  2. * ELF object format helpers
  3. *
  4. * Copyright (C) 2003-2007 Michael Urman
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  19. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef ELF_H_INCLUDED
  28. #define ELF_H_INCLUDED
  29. typedef struct elf_reloc_entry elf_reloc_entry;
  30. typedef struct elf_reloc_head elf_reloc_head;
  31. typedef struct elf_secthead elf_secthead;
  32. typedef struct elf_strtab_entry elf_strtab_entry;
  33. typedef struct elf_strtab_head elf_strtab_head;
  34. typedef struct elf_symtab_entry elf_symtab_entry;
  35. typedef struct elf_symtab_head elf_symtab_head;
  36. typedef struct elf_machine_handler elf_machine_handler;
  37. typedef unsigned long elf_address;
  38. typedef unsigned long elf_offset;
  39. typedef unsigned long elf_size;
  40. typedef unsigned long elf_section_info;
  41. typedef enum {
  42. ET_NONE = 0,
  43. ET_REL = 1, /* Relocatable */
  44. ET_EXEC = 2, /* Executable */
  45. ET_DYN = 3, /* Shared object */
  46. ET_CORE = 4, /* Core */
  47. ET_LOOS = 0xfe00, /* Environment specific */
  48. ET_HIOS = 0xfeff,
  49. ET_LOPROC = 0xff00, /* Processor specific */
  50. ET_HIPROC = 0xffff
  51. } elf_file_type;
  52. typedef enum {
  53. EM_NONE = 0,
  54. EM_M32 = 1, /* AT&T WE 32100 */
  55. EM_SPARC = 2, /* SPARC */
  56. EM_386 = 3, /* Intel 80386 */
  57. EM_68K = 4, /* Motorola 68000 */
  58. EM_88K = 5, /* Motorola 88000 */
  59. EM_860 = 7, /* Intel 80860 */
  60. EM_MIPS = 8, /* MIPS RS3000 */
  61. EM_S370 = 9, /* IBM System/370 */
  62. EM_MIPS_RS4_BE = 10, /* MIPS R4000 Big-Endian (dep)*/
  63. EM_PARISC = 15, /* HPPA */
  64. EM_SPARC32PLUS = 18, /* SPARC v8plus */
  65. EM_PPC = 20, /* PowerPC 32-bit */
  66. EM_PPC64 = 21, /* PowerPC 64-bit */
  67. EM_ARM = 40, /* ARM */
  68. EM_SPARCV9 = 43, /* SPARC v9 64-bit */
  69. EM_IA_64 = 50, /* Intel IA-64 */
  70. EM_X86_64 = 62, /* AMD x86-64 */
  71. EM_ALPHA = 0x9026 /* Alpha (no ABI) */
  72. } elf_machine;
  73. typedef enum {
  74. ELFMAG0 = 0x7f,
  75. ELFMAG1 = 0x45,
  76. ELFMAG2 = 0x4c,
  77. ELFMAG3 = 0x46
  78. } elf_magic;
  79. typedef enum {
  80. EV_NONE = 0, /* invalid */
  81. EV_CURRENT = 1 /* current */
  82. } elf_version;
  83. typedef enum {
  84. EI_MAG0 = 0, /* File id */
  85. EI_MAG1 = 1,
  86. EI_MAG2 = 2,
  87. EI_MAG3 = 3,
  88. EI_CLASS = 4, /* File class */
  89. EI_DATA = 5, /* Data encoding */
  90. EI_VERSION = 6, /* File version */
  91. EI_OSABI = 7, /* OS and ABI */
  92. EI_ABIVERSION = 8, /* version of ABI */
  93. EI_PAD = 9, /* Pad to end; start here */
  94. EI_NIDENT = 16 /* Sizeof e_ident[] */
  95. } elf_identification_index;
  96. typedef enum {
  97. ELFOSABI_SYSV = 0, /* System V ABI */
  98. ELFOSABI_HPUX = 1, /* HP-UX os */
  99. ELFOSABI_STANDALONE = 255 /* Standalone / embedded app */
  100. } elf_osabi_index;
  101. typedef enum {
  102. ELFCLASSNONE = 0, /* invalid */
  103. ELFCLASS32 = 1, /* 32-bit */
  104. ELFCLASS64 = 2 /* 64-bit */
  105. } elf_class;
  106. typedef enum {
  107. ELFDATANONE = 0,
  108. ELFDATA2LSB = 1,
  109. ELFDATA2MSB = 2
  110. } elf_data_encoding;
  111. /* elf section types - index of semantics */
  112. typedef enum {
  113. SHT_NULL = 0, /* inactive section - no associated data */
  114. SHT_PROGBITS = 1, /* defined by program for its own meaning */
  115. SHT_SYMTAB = 2, /* symbol table (primarily) for linking */
  116. SHT_STRTAB = 3, /* string table - symbols need names */
  117. SHT_RELA = 4, /* relocation entries w/ explicit addends */
  118. SHT_HASH = 5, /* symbol hash table - for dynamic linking */
  119. SHT_DYNAMIC = 6, /* information for dynamic linking */
  120. SHT_NOTE = 7, /* extra data marking the file somehow */
  121. SHT_NOBITS = 8, /* no stored data, but occupies runtime space */
  122. SHT_REL = 9, /* relocations entries w/o explicit addends */
  123. SHT_SHLIB = 10, /* reserved; unspecified semantics */
  124. SHT_DYNSYM = 11, /* like symtab, but more for dynamic linking */
  125. SHT_LOOS = 0x60000000, /* reserved for environment specific use */
  126. SHT_HIOS = 0x6fffffff,
  127. SHT_LOPROC = 0x70000000, /* reserved for processor specific semantics */
  128. SHT_HIPROC = 0x7fffffff/*,
  129. SHT_LOUSER = 0x80000000,*/ /* reserved for applications; safe */
  130. /*SHT_HIUSER = 0xffffffff*/
  131. } elf_section_type;
  132. /* elf section flags - bitfield of attributes */
  133. typedef enum {
  134. SHF_WRITE = 0x1, /* data should be writable at runtime */
  135. SHF_ALLOC = 0x2, /* occupies memory at runtime */
  136. SHF_EXECINSTR = 0x4, /* contains machine instructions */
  137. SHF_MERGE = 0x10, /* data can be merged */
  138. SHF_STRINGS = 0x20, /* contains 0-terminated strings */
  139. SHF_GROUP = 0x200, /* member of a section group */
  140. SHF_TLS = 0x400, /* thread local storage */
  141. SHF_MASKOS = 0x0f000000/*,*//* environment specific use */
  142. /*SHF_MASKPROC = 0xf0000000*/ /* bits reserved for processor specific needs */
  143. } elf_section_flags;
  144. /* elf section index - just the special ones */
  145. typedef enum {
  146. SHN_UNDEF = 0, /* undefined symbol; requires other global */
  147. SHN_LORESERVE = 0xff00, /* reserved for various semantics */
  148. SHN_LOPROC = 0xff00, /* reserved for processor specific semantics */
  149. SHN_HIPROC = 0xff1f,
  150. SHN_LOOS = 0xff20, /* reserved for environment specific use */
  151. SHN_HIOS = 0xff3f,
  152. SHN_ABS = 0xfff1, /* associated symbols don't change on reloc */
  153. SHN_COMMON = 0xfff2, /* associated symbols refer to unallocated */
  154. SHN_HIRESERVE = 0xffff
  155. } elf_section_index;
  156. /* elf symbol binding - index of visibility/behavior */
  157. typedef enum {
  158. STB_LOCAL = 0, /* invisible outside defining file */
  159. STB_GLOBAL = 1, /* visible to all combined object files */
  160. STB_WEAK = 2, /* global but lower precedence */
  161. STB_LOOS = 10, /* Environment specific use */
  162. STB_HIOS = 12,
  163. STB_LOPROC = 13, /* reserved for processor specific semantics */
  164. STB_HIPROC = 15
  165. } elf_symbol_binding;
  166. /* elf symbol type - index of classifications */
  167. typedef enum {
  168. STT_NOTYPE = 0, /* type not specified */
  169. STT_OBJECT = 1, /* data object such as a variable, array, etc */
  170. STT_FUNC = 2, /* a function or executable code */
  171. STT_SECTION = 3, /* a section: often for relocation, STB_LOCAL */
  172. STT_FILE = 4, /* often source filename: STB_LOCAL, SHN_ABS */
  173. STT_COMMON = 5, /* Uninitialized common block. */
  174. STT_TLS = 6, /* TLS object. */
  175. STT_NUM = 7,
  176. STT_LOOS = 10, /* Environment specific use */
  177. STT_HIOS = 12,
  178. STT_LOPROC = 13, /* reserved for processor specific semantics */
  179. STT_HIPROC = 15
  180. } elf_symbol_type;
  181. typedef enum {
  182. STN_UNDEF = 0
  183. } elf_symbol_index;
  184. /* elf symbol visibility - lower two bits of OTHER field */
  185. typedef enum {
  186. STV_DEFAULT = 0, /* Default symbol visibility rules */
  187. STV_INTERNAL = 1, /* Processor specific hidden class */
  188. STV_HIDDEN = 2, /* Sym unavailable in other modules */
  189. STV_PROTECTED = 3 /* Not preemptable, not exported */
  190. } elf_symbol_vis;
  191. /* internal only object definitions */
  192. #ifdef YASM_OBJFMT_ELF_INTERNAL
  193. #define ELF_VISIBILITY_MASK 0x03
  194. #define ELF_ST_VISIBILITY(v) ((v) & ELF_VISIBILITY_MASK)
  195. #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
  196. #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
  197. #define ELF32_ST_OTHER(vis) ELF_ST_VISIBILITY(vis)
  198. #define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
  199. #define ELF64_R_INFO(s,t) (((s)<<32) + ((t) & 0xffffffffL))
  200. #define ELF64_ST_OTHER(vis) ELF_ST_VISIBILITY(vis)
  201. #define EHDR32_SIZE 52
  202. #define EHDR64_SIZE 64
  203. #define EHDR_MAXSIZE 64
  204. #define SHDR32_SIZE 40
  205. #define SHDR64_SIZE 64
  206. #define SHDR_MAXSIZE 64
  207. #define SYMTAB32_SIZE 16
  208. #define SYMTAB64_SIZE 24
  209. #define SYMTAB_MAXSIZE 24
  210. #define SYMTAB32_ALIGN 4
  211. #define SYMTAB64_ALIGN 8
  212. #define RELOC32_SIZE 8
  213. #define RELOC32A_SIZE 12
  214. #define RELOC64_SIZE 16
  215. #define RELOC64A_SIZE 24
  216. #define RELOC_MAXSIZE 24
  217. #define RELOC32_ALIGN 4
  218. #define RELOC64_ALIGN 8
  219. /* elf relocation type - index of semantics
  220. *
  221. * A = Addend (r_addend for RELA, value at location for REL)
  222. * B = Base address
  223. * G = Offset into global offset table (GOT)
  224. * GOT = Address of the global offset table (GOT)
  225. * L = Location of procedure linkage table (PLT)
  226. * P = Location of location being relocated (r_offset)
  227. * S = Value of symbol
  228. */
  229. typedef enum {
  230. R_386_NONE = 0, /* none */
  231. R_386_32 = 1, /* word32, S + A */
  232. R_386_PC32 = 2, /* word32, S + A - P */
  233. R_386_GOT32 = 3, /* word32, G + A - P */
  234. R_386_PLT32 = 4, /* word32, L + A - P */
  235. R_386_COPY = 5, /* none */
  236. R_386_GLOB_DAT = 6, /* word32, S */
  237. R_386_JMP_SLOT = 7, /* word32, S */
  238. R_386_RELATIVE = 8, /* word32, B + A */
  239. R_386_GOTOFF = 9, /* word32, S + A - GOT */
  240. R_386_GOTPC = 10, /* word32, GOT + A - P */
  241. R_386_TLS_TPOFF = 14, /* Negative offset in static TLS block (GNU
  242. version) */
  243. R_386_TLS_IE = 15, /* Absolute address of GOT entry for negative
  244. static TLS block offset */
  245. R_386_TLS_GOTIE = 16, /* GOT entry for negative static TLS block
  246. offset */
  247. R_386_TLS_LE = 17, /* Negative offset relative to static TLS
  248. (GNU version) */
  249. R_386_TLS_GD = 18, /* Direct 32 bit for GNU version of GD TLS */
  250. R_386_TLS_LDM = 19, /* Direct 32 bit for GNU version of LD TLS
  251. in LE code */
  252. R_386_16 = 20, /* word16, S + A (GNU extension) */
  253. R_386_PC16 = 21, /* word16, S + A - P (GNU extension) */
  254. R_386_8 = 22, /* word8, S + A (GNU extension) */
  255. R_386_PC8 = 23, /* word8, S + A - P (GNU extension) */
  256. R_386_TLS_GD_32 = 24, /* Direct 32 bit for GD TLS */
  257. R_386_TLS_GD_PUSH = 25, /* Tag for pushl in GD TLS code */
  258. R_386_TLS_GD_CALL = 26, /* Relocation for call to */
  259. R_386_TLS_GD_POP = 27, /* Tag for popl in GD TLS code */
  260. R_386_TLS_LDM_32 = 28, /* Direct 32 bit for local dynamic code */
  261. R_386_TLS_LDM_PUSH = 29, /* Tag for pushl in LDM TLS code */
  262. R_386_TLS_LDM_CALL = 30, /* Relocation for call to */
  263. R_386_TLS_LDM_POP = 31, /* Tag for popl in LDM TLS code */
  264. R_386_TLS_LDO_32 = 32, /* Offset relative to TLS block */
  265. R_386_TLS_IE_32 = 33, /* GOT entry for static TLS block */
  266. R_386_TLS_LE_32 = 34, /* Offset relative to static TLS block */
  267. R_386_TLS_DTPMOD32 = 35, /* ID of module containing symbol */
  268. R_386_TLS_DTPOFF32 = 36, /* Offset in TLS block */
  269. R_386_TLS_TPOFF32 = 37, /* Offset in static TLS block */
  270. R_386_TLS_GOTDESC = 39,
  271. R_386_TLS_DESC_CALL = 40,
  272. R_386_TLS_DESC = 41
  273. } elf_386_relocation_type;
  274. typedef enum {
  275. R_X86_64_NONE = 0, /* none */
  276. R_X86_64_64 = 1, /* word64, S + A */
  277. R_X86_64_PC32 = 2, /* word32, S + A - P */
  278. R_X86_64_GOT32 = 3, /* word32, G + A */
  279. R_X86_64_PLT32 = 4, /* word32, L + A - P */
  280. R_X86_64_COPY = 5, /* none */
  281. R_X86_64_GLOB_DAT = 6, /* word64, S, set GOT entry to data address */
  282. R_X86_64_JMP_SLOT = 7, /* word64, S, set GOT entry to code address */
  283. R_X86_64_RELATIVE = 8, /* word64, B + A */
  284. R_X86_64_GOTPCREL = 9, /* word32, G + GOT + A - P */
  285. R_X86_64_32 = 10, /* word32 (zero extend), S + A */
  286. R_X86_64_32S = 11, /* word32 (sign extend), S + A */
  287. R_X86_64_16 = 12, /* word16, S + A */
  288. R_X86_64_PC16 = 13, /* word16, S + A - P */
  289. R_X86_64_8 = 14, /* word8, S + A */
  290. R_X86_64_PC8 = 15, /* word8, S + A - P */
  291. R_X86_64_DPTMOD64 = 16, /* word64, ID of module containing symbol */
  292. R_X86_64_DTPOFF64 = 17, /* word64, offset in TLS block */
  293. R_X86_64_TPOFF64 = 18, /* word64, offset in initial TLS block */
  294. R_X86_64_TLSGD = 19, /* word32, PC-rel offset to GD GOT block */
  295. R_X86_64_TLSLD = 20, /* word32, PC-rel offset to LD GOT block */
  296. R_X86_64_DTPOFF32 = 21, /* word32, offset to TLS block */
  297. R_X86_64_GOTTPOFF = 22, /* word32, PC-rel offset to IE GOT entry */
  298. R_X86_64_TPOFF32 = 23, /* word32, offset in initial TLS block */
  299. R_X86_64_PC64 = 24, /* word64, PC relative */
  300. R_X86_64_GOTOFF64 = 25, /* word64, offset to GOT */
  301. R_X86_64_GOTPC32 = 26, /* word32, signed pc relative to GOT */
  302. R_X86_64_GOT64 = 27, /* word64, GOT entry offset */
  303. R_X86_64_GOTPCREL64 = 28, /* word64, signed pc relative to GOT entry */
  304. R_X86_64_GOTPC64 = 29, /* word64, signed pc relative to GOT */
  305. R_X86_64_GOTPLT64 = 30, /* like GOT64, but indicates PLT entry needed */
  306. R_X86_64_PLTOFF64 = 31, /* word64, GOT relative offset to PLT entry */
  307. R_X86_64_GOTPC32_TLSDESC = 34, /* GOT offset for TLS descriptor */
  308. R_X86_64_TLSDESC_CALL = 35, /* Marker for call through TLS descriptor */
  309. R_X86_64_TLSDESC = 36 /* TLS descriptor */
  310. } elf_x86_64_relocation_type;
  311. struct elf_secthead {
  312. elf_section_type type;
  313. elf_section_flags flags;
  314. elf_address offset;
  315. yasm_intnum *size;
  316. elf_section_index link;
  317. elf_section_info info; /* see note ESD1 */
  318. unsigned long align;
  319. elf_size entsize;
  320. yasm_symrec *sym;
  321. elf_strtab_entry *name;
  322. elf_section_index index;
  323. elf_strtab_entry *rel_name;
  324. elf_section_index rel_index;
  325. elf_address rel_offset;
  326. unsigned long nreloc;
  327. };
  328. /* Note ESD1:
  329. * for section types SHT_REL, SHT_RELA:
  330. * link -> index of associated symbol table
  331. * info -> index of relocated section
  332. * for section types SHT_SYMTAB, SHT_DYNSYM:
  333. * link -> index of associated string table
  334. * info -> 1+index of last "local symbol" (bind == STB_LOCAL)
  335. * (for section type SHT_DNAMIC:
  336. * link -> index of string table
  337. * info -> 0 )
  338. * (for section type SHT_HASH:
  339. * link -> index of symbol table to which hash applies
  340. * info -> 0 )
  341. * for all others:
  342. * link -> SHN_UNDEF
  343. * info -> 0
  344. */
  345. struct elf_reloc_entry {
  346. yasm_reloc reloc;
  347. int rtype_rel;
  348. size_t valsize;
  349. yasm_intnum *addend;
  350. /*@null@*/ yasm_symrec *wrt;
  351. int is_GOT_sym;
  352. };
  353. STAILQ_HEAD(elf_strtab_head, elf_strtab_entry);
  354. struct elf_strtab_entry {
  355. STAILQ_ENTRY(elf_strtab_entry) qlink;
  356. unsigned long index;
  357. char *str;
  358. };
  359. STAILQ_HEAD(elf_symtab_head, elf_symtab_entry);
  360. struct elf_symtab_entry {
  361. STAILQ_ENTRY(elf_symtab_entry) qlink;
  362. int in_table;
  363. yasm_symrec *sym;
  364. yasm_section *sect;
  365. elf_strtab_entry *name;
  366. elf_address value;
  367. /*@dependent@*/ yasm_expr *xsize;
  368. elf_size size;
  369. elf_section_index index;
  370. elf_symbol_binding bind;
  371. elf_symbol_type type;
  372. elf_symbol_vis vis;
  373. elf_symbol_index symindex;
  374. };
  375. #endif /* defined(YASM_OBJFMT_ELF_INTERNAL) */
  376. extern const yasm_assoc_data_callback elf_section_data;
  377. extern const yasm_assoc_data_callback elf_symrec_data;
  378. extern const yasm_assoc_data_callback elf_ssym_symrec_data;
  379. const elf_machine_handler *elf_set_arch(struct yasm_arch *arch,
  380. yasm_symtab *symtab,
  381. int bits_pref);
  382. yasm_symrec *elf_get_special_sym(const char *name, const char *parser);
  383. /* reloc functions */
  384. int elf_is_wrt_sym_relative(yasm_symrec *wrt);
  385. int elf_is_wrt_pos_adjusted(yasm_symrec *wrt);
  386. elf_reloc_entry *elf_reloc_entry_create(yasm_symrec *sym,
  387. /*@null@*/ yasm_symrec *wrt,
  388. yasm_intnum *addr,
  389. int rel,
  390. size_t valsize,
  391. int is_GOT_sym);
  392. void elf_reloc_entry_destroy(void *entry);
  393. /* strtab functions */
  394. elf_strtab_entry *elf_strtab_entry_create(const char *str);
  395. void elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str);
  396. elf_strtab_head *elf_strtab_create(void);
  397. elf_strtab_entry *elf_strtab_append_str(elf_strtab_head *head, const char *str);
  398. void elf_strtab_destroy(elf_strtab_head *head);
  399. unsigned long elf_strtab_output_to_file(FILE *f, elf_strtab_head *head);
  400. /* symtab functions */
  401. elf_symtab_entry *elf_symtab_entry_create(elf_strtab_entry *name,
  402. struct yasm_symrec *sym);
  403. elf_symtab_head *elf_symtab_create(void);
  404. void elf_symtab_append_entry(elf_symtab_head *symtab, elf_symtab_entry *entry);
  405. void elf_symtab_insert_local_sym(elf_symtab_head *symtab,
  406. elf_symtab_entry *entry);
  407. void elf_symtab_destroy(elf_symtab_head *head);
  408. unsigned long elf_symtab_assign_indices(elf_symtab_head *symtab);
  409. unsigned long elf_symtab_write_to_file(FILE *f, elf_symtab_head *symtab,
  410. yasm_errwarns *errwarns);
  411. void elf_symtab_set_nonzero(elf_symtab_entry *entry,
  412. struct yasm_section *sect,
  413. elf_section_index sectidx,
  414. elf_symbol_binding bind,
  415. elf_symbol_type type,
  416. struct yasm_expr *size,
  417. elf_address *value);
  418. void elf_sym_set_visibility(elf_symtab_entry *entry,
  419. elf_symbol_vis vis);
  420. void elf_sym_set_type(elf_symtab_entry *entry, elf_symbol_type type);
  421. void elf_sym_set_size(elf_symtab_entry *entry, struct yasm_expr *size);
  422. int elf_sym_in_table(elf_symtab_entry *entry);
  423. /* section header functions */
  424. elf_secthead *elf_secthead_create(elf_strtab_entry *name,
  425. elf_section_type type,
  426. elf_section_flags flags,
  427. elf_address offset,
  428. elf_size size);
  429. void elf_secthead_destroy(elf_secthead *esd);
  430. unsigned long elf_secthead_write_to_file(FILE *f, elf_secthead *esd,
  431. elf_section_index sindex);
  432. void elf_secthead_append_reloc(yasm_section *sect, elf_secthead *shead,
  433. elf_reloc_entry *reloc);
  434. elf_section_type elf_secthead_get_type(elf_secthead *shead);
  435. void elf_secthead_set_typeflags(elf_secthead *shead, elf_section_type type,
  436. elf_section_flags flags);
  437. int elf_secthead_is_empty(elf_secthead *shead);
  438. struct yasm_symrec *elf_secthead_get_sym(elf_secthead *shead);
  439. unsigned long elf_secthead_get_align(const elf_secthead *shead);
  440. unsigned long elf_secthead_set_align(elf_secthead *shead, unsigned long align);
  441. elf_section_index elf_secthead_get_index(elf_secthead *shead);
  442. elf_section_info elf_secthead_set_info(elf_secthead *shead,
  443. elf_section_info info);
  444. elf_section_index elf_secthead_set_index(elf_secthead *shead,
  445. elf_section_index sectidx);
  446. elf_section_index elf_secthead_set_link(elf_secthead *shead,
  447. elf_section_index link);
  448. elf_section_index elf_secthead_set_rel_index(elf_secthead *shead,
  449. elf_section_index sectidx);
  450. elf_strtab_entry *elf_secthead_set_rel_name(elf_secthead *shead,
  451. elf_strtab_entry *entry);
  452. elf_size elf_secthead_set_entsize(elf_secthead *shead, elf_size size);
  453. struct yasm_symrec *elf_secthead_set_sym(elf_secthead *shead,
  454. struct yasm_symrec *sym);
  455. void elf_secthead_add_size(elf_secthead *shead, yasm_intnum *size);
  456. char *elf_secthead_name_reloc_section(const char *basesect);
  457. void elf_handle_reloc_addend(yasm_intnum *intn,
  458. elf_reloc_entry *reloc,
  459. unsigned long offset);
  460. unsigned long elf_secthead_write_rel_to_file(FILE *f, elf_section_index symtab,
  461. yasm_section *sect,
  462. elf_secthead *esd,
  463. elf_section_index sindex);
  464. unsigned long elf_secthead_write_relocs_to_file(FILE *f, yasm_section *sect,
  465. elf_secthead *shead,
  466. yasm_errwarns *errwarns);
  467. long elf_secthead_set_file_offset(elf_secthead *shead, long pos);
  468. /* program header function */
  469. unsigned long
  470. elf_proghead_get_size(void);
  471. unsigned long
  472. elf_proghead_write_to_file(FILE *f,
  473. elf_offset secthead_addr,
  474. unsigned long secthead_count,
  475. elf_section_index shstrtab_index);
  476. #endif /* ELF_H_INCLUDED */