aot_reloc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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_f32_to_i32), \
  93. REG_SYM(aot_intrinsic_f32_to_u32), \
  94. REG_SYM(aot_intrinsic_f32_to_i64), \
  95. REG_SYM(aot_intrinsic_f32_to_u64), \
  96. REG_SYM(aot_intrinsic_f64_to_i32), \
  97. REG_SYM(aot_intrinsic_f64_to_u32), \
  98. REG_SYM(aot_intrinsic_f64_to_i64), \
  99. REG_SYM(aot_intrinsic_f64_to_u64), \
  100. REG_SYM(aot_intrinsic_f32_to_f64), \
  101. REG_SYM(aot_intrinsic_f32_cmp), \
  102. REG_SYM(aot_intrinsic_f64_cmp), \
  103. REG_SYM(aot_intrinsic_i64_div_s), \
  104. REG_SYM(aot_intrinsic_i64_div_u), \
  105. REG_SYM(aot_intrinsic_i64_rem_s), \
  106. REG_SYM(aot_intrinsic_i64_rem_u), \
  107. REG_SYM(aot_intrinsic_i64_bit_or), \
  108. REG_SYM(aot_intrinsic_i64_bit_and), \
  109. REG_SYM(aot_intrinsic_i32_div_s), \
  110. REG_SYM(aot_intrinsic_i32_div_u), \
  111. REG_SYM(aot_intrinsic_i32_rem_s), \
  112. REG_SYM(aot_intrinsic_i32_rem_u), \
  113. #if WASM_ENABLE_STATIC_PGO != 0
  114. #define REG_LLVM_PGO_SYM() \
  115. { "__llvm_profile_instrument_target", llvm_profile_instrument_target }, \
  116. { "__llvm_profile_instrument_memop", llvm_profile_instrument_memop },
  117. #else
  118. #define REG_LLVM_PGO_SYM()
  119. #endif
  120. #define REG_COMMON_SYMBOLS \
  121. REG_SYM(aot_set_exception_with_id), \
  122. REG_SYM(aot_invoke_native), \
  123. REG_SYM(aot_call_indirect), \
  124. REG_SYM(aot_enlarge_memory), \
  125. REG_SYM(aot_set_exception), \
  126. REG_SYM(aot_check_app_addr_and_convert),\
  127. REG_SYM(wasm_runtime_quick_invoke_c_api_native),\
  128. { "memset", (void*)aot_memset }, \
  129. { "memmove", (void*)aot_memmove }, \
  130. { "memcpy", (void*)aot_memmove }, \
  131. { "sqrt", (void*)aot_sqrt }, \
  132. { "sqrtf", (void*)aot_sqrtf }, \
  133. REG_SYM(fmin), \
  134. REG_SYM(fminf), \
  135. REG_SYM(fmax), \
  136. REG_SYM(fmaxf), \
  137. REG_SYM(ceil), \
  138. REG_SYM(ceilf), \
  139. REG_SYM(floor), \
  140. REG_SYM(floorf), \
  141. REG_SYM(trunc), \
  142. REG_SYM(truncf), \
  143. REG_SYM(rint), \
  144. REG_SYM(rintf), \
  145. REG_BULK_MEMORY_SYM() \
  146. REG_ATOMIC_WAIT_SYM() \
  147. REG_REF_TYPES_SYM() \
  148. REG_AOT_TRACE_SYM() \
  149. REG_INTRINSIC_SYM() \
  150. REG_LLVM_PGO_SYM() \
  151. #define CHECK_RELOC_OFFSET(data_size) do { \
  152. if (!check_reloc_offset(target_section_size, \
  153. reloc_offset, data_size, \
  154. error_buf, error_buf_size)) \
  155. return false; \
  156. } while (0)
  157. SymbolMap *
  158. get_target_symbol_map(uint32 *sym_num);
  159. uint32
  160. get_plt_table_size();
  161. void
  162. init_plt_table(uint8 *plt);
  163. void
  164. get_current_target(char *target_buf, uint32 target_buf_size);
  165. bool
  166. apply_relocation(AOTModule *module,
  167. uint8 *target_section_addr, uint32 target_section_size,
  168. uint64 reloc_offset, int64 reloc_addend,
  169. uint32 reloc_type, void *symbol_addr, int32 symbol_index,
  170. char *error_buf, uint32 error_buf_size);
  171. /* clang-format off */
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif /* end of _AOT_RELOC_H_ */