aot_reloc.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _AOT_RELOC_H_
  6. #define _AOT_RELOC_H_
  7. #include "aot_runtime.h"
  8. #include "aot_intrinsic.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef struct {
  13. const char *symbol_name;
  14. void *symbol_addr;
  15. } SymbolMap;
  16. /* clang-format off */
  17. #define REG_SYM(symbol) { #symbol, (void *)symbol }
  18. #if WASM_ENABLE_BULK_MEMORY != 0
  19. #define REG_BULK_MEMORY_SYM() \
  20. REG_SYM(aot_memory_init), \
  21. REG_SYM(aot_data_drop),
  22. #else
  23. #define REG_BULK_MEMORY_SYM()
  24. #endif
  25. #if WASM_ENABLE_SHARED_MEMORY != 0
  26. #include "wasm_shared_memory.h"
  27. #define REG_ATOMIC_WAIT_SYM() \
  28. REG_SYM(wasm_runtime_atomic_wait), \
  29. REG_SYM(wasm_runtime_atomic_notify),
  30. #else
  31. #define REG_ATOMIC_WAIT_SYM()
  32. #endif
  33. #if WASM_ENABLE_REF_TYPES != 0
  34. #define REG_REF_TYPES_SYM() \
  35. REG_SYM(aot_drop_table_seg), \
  36. REG_SYM(aot_table_init), \
  37. REG_SYM(aot_table_copy), \
  38. REG_SYM(aot_table_fill), \
  39. REG_SYM(aot_table_grow),
  40. #else
  41. #define REG_REF_TYPES_SYM()
  42. #endif
  43. #if (WASM_ENABLE_PERF_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0)
  44. #define REG_AOT_TRACE_SYM() \
  45. REG_SYM(aot_alloc_frame), \
  46. REG_SYM(aot_free_frame),
  47. #else
  48. #define REG_AOT_TRACE_SYM()
  49. #endif
  50. #define REG_INTRINSIC_SYM() \
  51. REG_SYM(aot_intrinsic_fabs_f32), \
  52. REG_SYM(aot_intrinsic_fabs_f64), \
  53. REG_SYM(aot_intrinsic_floor_f32), \
  54. REG_SYM(aot_intrinsic_floor_f64), \
  55. REG_SYM(aot_intrinsic_ceil_f32), \
  56. REG_SYM(aot_intrinsic_ceil_f64), \
  57. REG_SYM(aot_intrinsic_trunc_f32), \
  58. REG_SYM(aot_intrinsic_trunc_f64), \
  59. REG_SYM(aot_intrinsic_rint_f32), \
  60. REG_SYM(aot_intrinsic_rint_f64), \
  61. REG_SYM(aot_intrinsic_sqrt_f32), \
  62. REG_SYM(aot_intrinsic_sqrt_f64), \
  63. REG_SYM(aot_intrinsic_copysign_f32), \
  64. REG_SYM(aot_intrinsic_copysign_f64), \
  65. REG_SYM(aot_intrinsic_fadd_f32), \
  66. REG_SYM(aot_intrinsic_fadd_f64), \
  67. REG_SYM(aot_intrinsic_fsub_f32), \
  68. REG_SYM(aot_intrinsic_fsub_f64), \
  69. REG_SYM(aot_intrinsic_fmul_f32), \
  70. REG_SYM(aot_intrinsic_fmul_f64), \
  71. REG_SYM(aot_intrinsic_fdiv_f32), \
  72. REG_SYM(aot_intrinsic_fdiv_f64), \
  73. REG_SYM(aot_intrinsic_fmin_f32), \
  74. REG_SYM(aot_intrinsic_fmin_f64), \
  75. REG_SYM(aot_intrinsic_fmax_f32), \
  76. REG_SYM(aot_intrinsic_fmax_f64), \
  77. REG_SYM(aot_intrinsic_clz_i32), \
  78. REG_SYM(aot_intrinsic_clz_i64), \
  79. REG_SYM(aot_intrinsic_ctz_i32), \
  80. REG_SYM(aot_intrinsic_ctz_i64), \
  81. REG_SYM(aot_intrinsic_popcnt_i32), \
  82. REG_SYM(aot_intrinsic_popcnt_i64), \
  83. REG_SYM(aot_intrinsic_i32_to_f32), \
  84. REG_SYM(aot_intrinsic_u32_to_f32), \
  85. REG_SYM(aot_intrinsic_i32_to_f64), \
  86. REG_SYM(aot_intrinsic_u32_to_f64), \
  87. REG_SYM(aot_intrinsic_i64_to_f32), \
  88. REG_SYM(aot_intrinsic_u64_to_f32), \
  89. REG_SYM(aot_intrinsic_i64_to_f64), \
  90. REG_SYM(aot_intrinsic_u64_to_f64), \
  91. REG_SYM(aot_intrinsic_f64_to_f32), \
  92. REG_SYM(aot_intrinsic_f64_to_u32), \
  93. REG_SYM(aot_intrinsic_f32_to_f64), \
  94. REG_SYM(aot_intrinsic_f32_cmp), \
  95. REG_SYM(aot_intrinsic_f64_cmp), \
  96. #define REG_COMMON_SYMBOLS \
  97. REG_SYM(aot_set_exception_with_id), \
  98. REG_SYM(aot_invoke_native), \
  99. REG_SYM(aot_call_indirect), \
  100. REG_SYM(aot_call_indirect_with_type), \
  101. REG_SYM(aot_enlarge_memory), \
  102. REG_SYM(aot_set_exception), \
  103. REG_SYM(aot_resolve_function), \
  104. { "memset", (void*)aot_memset}, \
  105. { "memmove", (void*)aot_memmove}, \
  106. { "memcpy", (void*)aot_memmove }, \
  107. REG_SYM(fmin), \
  108. REG_SYM(fminf), \
  109. REG_SYM(fmax), \
  110. REG_SYM(fmaxf), \
  111. REG_SYM(ceil), \
  112. REG_SYM(ceilf), \
  113. REG_SYM(floor), \
  114. REG_SYM(floorf), \
  115. REG_SYM(trunc), \
  116. REG_SYM(truncf), \
  117. REG_SYM(rint), \
  118. REG_SYM(rintf), \
  119. REG_BULK_MEMORY_SYM() \
  120. REG_ATOMIC_WAIT_SYM() \
  121. REG_REF_TYPES_SYM() \
  122. REG_AOT_TRACE_SYM() \
  123. REG_INTRINSIC_SYM() \
  124. #define CHECK_RELOC_OFFSET(data_size) do { \
  125. if (!check_reloc_offset(target_section_size, \
  126. reloc_offset, data_size, \
  127. error_buf, error_buf_size)) \
  128. return false; \
  129. } while (0)
  130. SymbolMap *
  131. get_target_symbol_map(uint32 *sym_num);
  132. uint32
  133. get_plt_table_size();
  134. void
  135. init_plt_table(uint8 *plt);
  136. void
  137. get_current_target(char *target_buf, uint32 target_buf_size);
  138. bool
  139. apply_relocation(AOTModule *module,
  140. uint8 *target_section_addr, uint32 target_section_size,
  141. uint64 reloc_offset, int64 reloc_addend,
  142. uint32 reloc_type, void *symbol_addr, int32 symbol_index,
  143. char *error_buf, uint32 error_buf_size);
  144. /* clang-format off */
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* end of _AOT_RELOC_H_ */