2020-02-27 08:38:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
*/
|
|
|
|
|
2021-10-08 09:47:11 +00:00
|
|
|
#ifndef _AOT_RELOC_H_
|
|
|
|
#define _AOT_RELOC_H_
|
|
|
|
|
2020-02-27 08:38:44 +00:00
|
|
|
#include "aot_runtime.h"
|
2021-08-12 09:44:39 +00:00
|
|
|
#include "aot_intrinsic.h"
|
2020-02-27 08:38:44 +00:00
|
|
|
|
2021-10-08 09:47:11 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-02-27 08:38:44 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *symbol_name;
|
|
|
|
void *symbol_addr;
|
|
|
|
} SymbolMap;
|
|
|
|
|
2021-10-08 09:47:11 +00:00
|
|
|
/* clang-format off */
|
|
|
|
#define REG_SYM(symbol) { #symbol, (void *)symbol }
|
2020-02-27 08:38:44 +00:00
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
#if WASM_ENABLE_BULK_MEMORY != 0
|
2020-08-03 03:30:26 +00:00
|
|
|
#define REG_BULK_MEMORY_SYM() \
|
2020-06-02 06:53:06 +00:00
|
|
|
REG_SYM(aot_memory_init), \
|
2020-08-03 03:30:26 +00:00
|
|
|
REG_SYM(aot_data_drop),
|
|
|
|
#else
|
|
|
|
#define REG_BULK_MEMORY_SYM()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
|
|
|
#include "wasm_shared_memory.h"
|
|
|
|
#define REG_ATOMIC_WAIT_SYM() \
|
|
|
|
REG_SYM(wasm_runtime_atomic_wait), \
|
|
|
|
REG_SYM(wasm_runtime_atomic_notify),
|
2020-06-02 06:53:06 +00:00
|
|
|
#else
|
2020-08-03 03:30:26 +00:00
|
|
|
#define REG_ATOMIC_WAIT_SYM()
|
|
|
|
#endif
|
|
|
|
|
2021-04-15 03:29:20 +00:00
|
|
|
#if WASM_ENABLE_REF_TYPES != 0
|
|
|
|
#define REG_REF_TYPES_SYM() \
|
|
|
|
REG_SYM(aot_drop_table_seg), \
|
|
|
|
REG_SYM(aot_table_init), \
|
|
|
|
REG_SYM(aot_table_copy), \
|
|
|
|
REG_SYM(aot_table_fill), \
|
|
|
|
REG_SYM(aot_table_grow),
|
|
|
|
#else
|
|
|
|
#define REG_REF_TYPES_SYM()
|
|
|
|
#endif
|
|
|
|
|
2021-01-18 05:23:10 +00:00
|
|
|
#if (WASM_ENABLE_PERF_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0)
|
|
|
|
#define REG_AOT_TRACE_SYM() \
|
|
|
|
REG_SYM(aot_alloc_frame), \
|
|
|
|
REG_SYM(aot_free_frame),
|
|
|
|
#else
|
|
|
|
#define REG_AOT_TRACE_SYM()
|
|
|
|
#endif
|
|
|
|
|
2021-08-12 09:44:39 +00:00
|
|
|
#define REG_INTRINSIC_SYM() \
|
|
|
|
REG_SYM(aot_intrinsic_fabs_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fabs_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_floor_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_floor_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_ceil_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_ceil_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_trunc_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_trunc_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_rint_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_rint_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_sqrt_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_sqrt_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_copysign_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_copysign_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_fadd_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fadd_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_fsub_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fsub_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_fmul_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fmul_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_fdiv_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fdiv_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_fmin_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fmin_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_fmax_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_fmax_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_clz_i32), \
|
|
|
|
REG_SYM(aot_intrinsic_clz_i64), \
|
|
|
|
REG_SYM(aot_intrinsic_ctz_i32), \
|
|
|
|
REG_SYM(aot_intrinsic_ctz_i64), \
|
|
|
|
REG_SYM(aot_intrinsic_popcnt_i32), \
|
|
|
|
REG_SYM(aot_intrinsic_popcnt_i64), \
|
2021-09-02 08:39:53 +00:00
|
|
|
REG_SYM(aot_intrinsic_i32_to_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_u32_to_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_i32_to_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_u32_to_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_i64_to_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_u64_to_f32), \
|
|
|
|
REG_SYM(aot_intrinsic_i64_to_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_u64_to_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_f64_to_f32), \
|
2021-12-08 10:43:08 +00:00
|
|
|
REG_SYM(aot_intrinsic_f32_to_i32), \
|
|
|
|
REG_SYM(aot_intrinsic_f32_to_u32), \
|
2022-12-30 07:21:25 +00:00
|
|
|
REG_SYM(aot_intrinsic_f32_to_i64), \
|
|
|
|
REG_SYM(aot_intrinsic_f32_to_u64), \
|
2021-11-30 09:10:14 +00:00
|
|
|
REG_SYM(aot_intrinsic_f64_to_i32), \
|
2021-09-02 08:39:53 +00:00
|
|
|
REG_SYM(aot_intrinsic_f64_to_u32), \
|
2022-11-01 12:29:07 +00:00
|
|
|
REG_SYM(aot_intrinsic_f64_to_i64), \
|
|
|
|
REG_SYM(aot_intrinsic_f64_to_u64), \
|
2021-09-02 08:39:53 +00:00
|
|
|
REG_SYM(aot_intrinsic_f32_to_f64), \
|
|
|
|
REG_SYM(aot_intrinsic_f32_cmp), \
|
|
|
|
REG_SYM(aot_intrinsic_f64_cmp), \
|
2022-08-12 03:09:06 +00:00
|
|
|
REG_SYM(aot_intrinsic_i64_div_s), \
|
|
|
|
REG_SYM(aot_intrinsic_i64_div_u), \
|
|
|
|
REG_SYM(aot_intrinsic_i64_rem_s), \
|
|
|
|
REG_SYM(aot_intrinsic_i64_rem_u), \
|
2022-11-14 03:58:38 +00:00
|
|
|
REG_SYM(aot_intrinsic_i64_bit_or), \
|
|
|
|
REG_SYM(aot_intrinsic_i64_bit_and), \
|
2022-12-13 02:48:51 +00:00
|
|
|
REG_SYM(aot_intrinsic_i32_div_s), \
|
2022-10-31 09:25:24 +00:00
|
|
|
REG_SYM(aot_intrinsic_i32_div_u), \
|
2022-12-08 01:38:20 +00:00
|
|
|
REG_SYM(aot_intrinsic_i32_rem_s), \
|
|
|
|
REG_SYM(aot_intrinsic_i32_rem_u), \
|
2021-08-12 09:44:39 +00:00
|
|
|
|
2020-02-27 08:38:44 +00:00
|
|
|
#define REG_COMMON_SYMBOLS \
|
|
|
|
REG_SYM(aot_set_exception_with_id), \
|
2020-03-04 12:12:38 +00:00
|
|
|
REG_SYM(aot_invoke_native), \
|
2020-03-24 11:04:29 +00:00
|
|
|
REG_SYM(aot_call_indirect), \
|
2021-04-15 03:29:20 +00:00
|
|
|
REG_SYM(aot_enlarge_memory), \
|
|
|
|
REG_SYM(aot_set_exception), \
|
2022-02-23 06:58:32 +00:00
|
|
|
REG_SYM(aot_check_app_addr_and_convert),\
|
2021-11-13 08:59:35 +00:00
|
|
|
{ "memset", (void*)aot_memset }, \
|
|
|
|
{ "memmove", (void*)aot_memmove }, \
|
|
|
|
{ "memcpy", (void*)aot_memmove }, \
|
2022-11-08 04:42:19 +00:00
|
|
|
{ "sqrt", (void*)aot_sqrt }, \
|
|
|
|
{ "sqrtf", (void*)aot_sqrtf }, \
|
2020-02-27 08:38:44 +00:00
|
|
|
REG_SYM(fmin), \
|
|
|
|
REG_SYM(fminf), \
|
|
|
|
REG_SYM(fmax), \
|
|
|
|
REG_SYM(fmaxf), \
|
|
|
|
REG_SYM(ceil), \
|
|
|
|
REG_SYM(ceilf), \
|
|
|
|
REG_SYM(floor), \
|
|
|
|
REG_SYM(floorf), \
|
|
|
|
REG_SYM(trunc), \
|
|
|
|
REG_SYM(truncf), \
|
|
|
|
REG_SYM(rint), \
|
2020-08-03 03:30:26 +00:00
|
|
|
REG_SYM(rintf), \
|
|
|
|
REG_BULK_MEMORY_SYM() \
|
2021-01-18 05:23:10 +00:00
|
|
|
REG_ATOMIC_WAIT_SYM() \
|
2021-04-15 03:29:20 +00:00
|
|
|
REG_REF_TYPES_SYM() \
|
2021-08-12 09:44:39 +00:00
|
|
|
REG_AOT_TRACE_SYM() \
|
|
|
|
REG_INTRINSIC_SYM() \
|
2020-02-27 08:38:44 +00:00
|
|
|
|
2021-10-08 09:47:11 +00:00
|
|
|
#define CHECK_RELOC_OFFSET(data_size) do { \
|
|
|
|
if (!check_reloc_offset(target_section_size, \
|
|
|
|
reloc_offset, data_size, \
|
|
|
|
error_buf, error_buf_size)) \
|
|
|
|
return false; \
|
2020-02-27 08:38:44 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
SymbolMap *
|
|
|
|
get_target_symbol_map(uint32 *sym_num);
|
|
|
|
|
|
|
|
uint32
|
|
|
|
get_plt_table_size();
|
|
|
|
|
|
|
|
void
|
|
|
|
init_plt_table(uint8 *plt);
|
|
|
|
|
|
|
|
void
|
|
|
|
get_current_target(char *target_buf, uint32 target_buf_size);
|
|
|
|
|
|
|
|
bool
|
|
|
|
apply_relocation(AOTModule *module,
|
|
|
|
uint8 *target_section_addr, uint32 target_section_size,
|
2021-11-15 02:57:37 +00:00
|
|
|
uint64 reloc_offset, int64 reloc_addend,
|
2020-02-27 08:38:44 +00:00
|
|
|
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
|
|
|
char *error_buf, uint32 error_buf_size);
|
2021-10-08 09:47:11 +00:00
|
|
|
/* clang-format off */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2020-02-27 08:38:44 +00:00
|
|
|
|
2021-10-08 09:47:11 +00:00
|
|
|
#endif /* end of _AOT_RELOC_H_ */
|