outelf.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2009 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. /*
  34. * Internal definitions common to outelf32 and outelf64
  35. */
  36. #ifndef OUTPUT_OUTELF_H
  37. #define OUTPUT_OUTELF_H
  38. #include "elf.h"
  39. #include "rbtree.h"
  40. #include "saa.h"
  41. /* symbol binding */
  42. #define SYM_GLOBAL ELF32_ST_MKBIND(STB_GLOBAL)
  43. #define SYM_LOCAL ELF32_ST_MKBIND(STB_LOCAL)
  44. #define GLOBAL_TEMP_BASE 0x40000000 /* bigger than any sane symbol index */
  45. /* alignment of sections in file */
  46. #define SEC_FILEALIGN 16
  47. /* this stuff is needed for the dwarf/stabs debugging format */
  48. #define TY_DEBUGSYMLIN 0x40 /* internal call to debug_out */
  49. /* Known sections with nonstandard defaults */
  50. struct elf_known_section {
  51. const char *name; /* Name of section */
  52. int type; /* Section type (SHT_) */
  53. uint32_t flags; /* Section flags (SHF_) */
  54. uint32_t align; /* Section alignment */
  55. };
  56. extern const struct elf_known_section elf_known_sections[];
  57. /*
  58. * Special ELF sections (after the real sections but before debugging ones)
  59. */
  60. #define sec_shstrtab (nsects + 1)
  61. #define sec_symtab (nsects + 2)
  62. #define sec_strtab (nsects + 3)
  63. #define sec_numspecial 3
  64. /*
  65. * Debugging ELF sections (last in the file)
  66. */
  67. /* stabs */
  68. #define sec_stab (nsections-3)
  69. #define sec_stabstr (nsections-2)
  70. #define sec_rel_stab (nsections-1)
  71. /* stabs symbol table format */
  72. struct stabentry {
  73. uint32_t n_strx;
  74. uint8_t n_type;
  75. uint8_t n_other;
  76. uint16_t n_desc;
  77. uint32_t n_value;
  78. };
  79. /* dwarf */
  80. #define sec_debug_aranges (nsections-10)
  81. #define sec_rela_debug_aranges (nsections-9)
  82. #define sec_debug_pubnames (nsections-8)
  83. #define sec_debug_info (nsections-7)
  84. #define sec_rela_debug_info (nsections-6)
  85. #define sec_debug_abbrev (nsections-5)
  86. #define sec_debug_line (nsections-4)
  87. #define sec_rela_debug_line (nsections-3)
  88. #define sec_debug_frame (nsections-2)
  89. #define sec_debug_loc (nsections-1)
  90. extern uint8_t elf_osabi;
  91. extern uint8_t elf_abiver;
  92. #define WRITE_STAB(p,n_strx,n_type,n_other,n_desc,n_value) \
  93. do { \
  94. WRITELONG(p, n_strx); \
  95. WRITECHAR(p, n_type); \
  96. WRITECHAR(p, n_other); \
  97. WRITESHORT(p, n_desc); \
  98. WRITELONG(p, n_value); \
  99. } while (0)
  100. struct elf_reloc {
  101. struct elf_reloc *next;
  102. int64_t address; /* relative to _start_ of section */
  103. int64_t symbol; /* symbol index */
  104. int64_t offset; /* symbol addend */
  105. int type; /* type of relocation */
  106. };
  107. struct elf_symbol {
  108. struct rbtree symv; /* symbol value and symbol rbtree */
  109. int32_t strpos; /* string table position of name */
  110. int32_t section; /* section ID of the symbol */
  111. int type; /* symbol type */
  112. int other; /* symbol visibility */
  113. int32_t size; /* size of symbol */
  114. int32_t globnum; /* symbol table offset if global */
  115. struct elf_symbol *nextfwd; /* list of unresolved-size symbols */
  116. char *name; /* used temporarily if in above list */
  117. };
  118. struct elf_section {
  119. struct SAA *data;
  120. uint64_t len;
  121. uint64_t size;
  122. uint64_t nrelocs;
  123. int32_t index;
  124. int type; /* SHT_PROGBITS or SHT_NOBITS */
  125. uint64_t align; /* alignment: power of two */
  126. uint64_t flags; /* section flags */
  127. char *name;
  128. struct SAA *rel;
  129. uint64_t rellen;
  130. struct elf_reloc *head;
  131. struct elf_reloc **tail;
  132. struct rbtree *gsyms; /* global symbols in section */
  133. };
  134. #endif /* OUTPUT_OUTELF_H */