elf-machine.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * ELF object machine specific format helpers
  3. *
  4. * Copyright (C) 2004-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_MACHINE_H_INCLUDED
  28. #define ELF_MACHINE_H_INCLUDED
  29. #define YASM_WRITE_32I_L(p, i) do {\
  30. assert(yasm_intnum_check_size(i, 32, 0, 2)); \
  31. yasm_intnum_get_sized(i, p, 4, 32, 0, 0, 0); \
  32. p += 4; } while (0)
  33. #define YASM_WRITE_64I_L(p, i) do {\
  34. assert(yasm_intnum_check_size(i, 64, 0, 2)); \
  35. yasm_intnum_get_sized(i, p, 8, 64, 0, 0, 0); \
  36. p += 8; } while (0)
  37. #define YASM_WRITE_64C_L(p, hi, lo) do {\
  38. YASM_WRITE_32_L(p, lo); \
  39. YASM_WRITE_32_L(p, hi); } while (0)
  40. #define YASM_WRITE_64Z_L(p, i) YASM_WRITE_64C_L(p, 0, i)
  41. typedef int(*func_accepts_reloc)(size_t val, yasm_symrec *wrt);
  42. typedef void(*func_write_symtab_entry)(unsigned char *bufp,
  43. elf_symtab_entry *entry,
  44. yasm_intnum *value_intn,
  45. yasm_intnum *size_intn);
  46. typedef void(*func_write_secthead)(unsigned char *bufp, elf_secthead *shead);
  47. typedef void(*func_write_secthead_rel)(unsigned char *bufp,
  48. elf_secthead *shead,
  49. elf_section_index symtab_idx,
  50. elf_section_index sindex);
  51. typedef void(*func_handle_reloc_addend)(yasm_intnum *intn,
  52. elf_reloc_entry *reloc,
  53. unsigned long offset);
  54. typedef unsigned int(*func_map_reloc_info_to_type)(elf_reloc_entry *reloc);
  55. typedef void(*func_write_reloc)(unsigned char *bufp,
  56. elf_reloc_entry *reloc,
  57. unsigned int r_type,
  58. unsigned int r_sym);
  59. typedef void (*func_write_proghead)(unsigned char **bufpp,
  60. elf_offset secthead_addr,
  61. unsigned long secthead_count,
  62. elf_section_index shstrtab_index);
  63. enum {
  64. ELF_SSYM_SYM_RELATIVE = 1 << 0,
  65. ELF_SSYM_CURPOS_ADJUST = 1 << 1,
  66. ELF_SSYM_THREAD_LOCAL = 1 << 2
  67. };
  68. typedef struct {
  69. const char *name; /* should be something like ..name */
  70. const int sym_rel; /* symbol or section-relative? */
  71. const unsigned int reloc; /* relocation type */
  72. const unsigned int size; /* legal data size */
  73. } elf_machine_ssym;
  74. struct elf_machine_handler {
  75. const char *arch;
  76. const char *machine;
  77. const char *reloc_section_prefix;
  78. const unsigned long symtab_entry_size;
  79. const unsigned long symtab_entry_align;
  80. const unsigned long reloc_entry_size;
  81. const unsigned long secthead_size;
  82. const unsigned long proghead_size;
  83. func_accepts_reloc accepts_reloc;
  84. func_write_symtab_entry write_symtab_entry;
  85. func_write_secthead write_secthead;
  86. func_write_secthead_rel write_secthead_rel;
  87. func_handle_reloc_addend handle_reloc_addend;
  88. func_map_reloc_info_to_type map_reloc_info_to_type;
  89. func_write_reloc write_reloc;
  90. func_write_proghead write_proghead;
  91. elf_machine_ssym *ssyms; /* array of "special" syms */
  92. const size_t num_ssyms; /* size of array */
  93. const int bits; /* usually 32 or 64 */
  94. };
  95. #endif /* ELF_MACHINE_H_INCLUDED */