mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2026-04-18 18:18:44 +00:00
Merge d08ab66060 into 4b306f0fc3
This commit is contained in:
commit
b2965c5d13
|
|
@ -45,6 +45,7 @@ typedef struct AOTSymbolList {
|
||||||
AOTSymbolNode *head;
|
AOTSymbolNode *head;
|
||||||
AOTSymbolNode *end;
|
AOTSymbolNode *end;
|
||||||
uint32 len;
|
uint32 len;
|
||||||
|
void *hash_table;
|
||||||
} AOTSymbolList;
|
} AOTSymbolList;
|
||||||
|
|
||||||
/* AOT object data */
|
/* AOT object data */
|
||||||
|
|
@ -989,46 +990,81 @@ get_relocation_groups_size(AOTObjectData *obj_data,
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return the index (in order of insertion) of the symbol,
|
#define SYMBOL_HASH_SIZE 4096
|
||||||
create if not exits, -1 if failed */
|
#define SYMBOL_HASH_MASK (SYMBOL_HASH_SIZE - 1)
|
||||||
|
|
||||||
|
typedef struct AOTSymbolHashEntry {
|
||||||
|
const char *symbol;
|
||||||
|
uint32 index;
|
||||||
|
struct AOTSymbolHashEntry *hash_next;
|
||||||
|
} AOTSymbolHashEntry;
|
||||||
|
|
||||||
static uint32
|
static uint32
|
||||||
get_relocation_symbol_index(const char *symbol_name, bool *is_new,
|
get_relocation_symbol_index(const char *symbol_name, bool *is_new,
|
||||||
AOTSymbolList *symbol_list)
|
AOTSymbolList *symbol_list)
|
||||||
{
|
{
|
||||||
AOTSymbolNode *sym;
|
uint32 index;
|
||||||
uint32 index = 0;
|
AOTSymbolHashEntry **ht;
|
||||||
|
if (!symbol_list->hash_table) {
|
||||||
sym = symbol_list->head;
|
symbol_list->hash_table = wasm_runtime_malloc(
|
||||||
|
sizeof(AOTSymbolHashEntry *) * SYMBOL_HASH_SIZE);
|
||||||
|
if (symbol_list->hash_table)
|
||||||
|
memset(symbol_list->hash_table, 0,
|
||||||
|
sizeof(AOTSymbolHashEntry *) * SYMBOL_HASH_SIZE);
|
||||||
|
}
|
||||||
|
ht = (AOTSymbolHashEntry **)symbol_list->hash_table;
|
||||||
|
if (ht) {
|
||||||
|
uint32 bucket = wasm_string_hash(symbol_name) & SYMBOL_HASH_MASK;
|
||||||
|
AOTSymbolHashEntry *entry = ht[bucket];
|
||||||
|
while (entry) {
|
||||||
|
if (!strcmp(entry->symbol, symbol_name)) {
|
||||||
|
if (is_new)
|
||||||
|
*is_new = false;
|
||||||
|
return entry->index;
|
||||||
|
}
|
||||||
|
entry = entry->hash_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AOTSymbolNode *sym = symbol_list->head;
|
||||||
|
uint32 idx = 0;
|
||||||
while (sym) {
|
while (sym) {
|
||||||
if (!strcmp(sym->symbol, symbol_name)) {
|
if (!strcmp(sym->symbol, symbol_name)) {
|
||||||
if (is_new)
|
if (is_new)
|
||||||
*is_new = false;
|
*is_new = false;
|
||||||
return index;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
sym = sym->next;
|
sym = sym->next;
|
||||||
index++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Not found in symbol_list, add it */
|
index = symbol_list->len;
|
||||||
sym = wasm_runtime_malloc(sizeof(AOTSymbolNode));
|
{
|
||||||
if (!sym) {
|
AOTSymbolNode *sym = wasm_runtime_malloc(sizeof(AOTSymbolNode));
|
||||||
|
if (!sym)
|
||||||
return (uint32)-1;
|
return (uint32)-1;
|
||||||
}
|
|
||||||
|
|
||||||
memset(sym, 0, sizeof(AOTSymbolNode));
|
memset(sym, 0, sizeof(AOTSymbolNode));
|
||||||
sym->symbol = (char *)symbol_name;
|
sym->symbol = (char *)symbol_name;
|
||||||
sym->str_len = (uint32)strlen(symbol_name);
|
sym->str_len = (uint32)strlen(symbol_name);
|
||||||
|
if (!symbol_list->head)
|
||||||
if (!symbol_list->head) {
|
|
||||||
symbol_list->head = symbol_list->end = sym;
|
symbol_list->head = symbol_list->end = sym;
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
symbol_list->end->next = sym;
|
symbol_list->end->next = sym;
|
||||||
symbol_list->end = sym;
|
symbol_list->end = sym;
|
||||||
}
|
}
|
||||||
symbol_list->len++;
|
symbol_list->len++;
|
||||||
|
}
|
||||||
|
if (ht) {
|
||||||
|
uint32 bucket = wasm_string_hash(symbol_name) & SYMBOL_HASH_MASK;
|
||||||
|
AOTSymbolHashEntry *entry =
|
||||||
|
wasm_runtime_malloc(sizeof(AOTSymbolHashEntry));
|
||||||
|
if (!entry)
|
||||||
|
return (uint32)-1;
|
||||||
|
entry->symbol = symbol_name;
|
||||||
|
entry->index = index;
|
||||||
|
entry->hash_next = ht[bucket];
|
||||||
|
ht[bucket] = entry;
|
||||||
|
}
|
||||||
if (is_new)
|
if (is_new)
|
||||||
*is_new = true;
|
*is_new = true;
|
||||||
return index;
|
return index;
|
||||||
|
|
@ -4324,6 +4360,20 @@ destroy_relocation_symbol_list(AOTSymbolList *symbol_list)
|
||||||
wasm_runtime_free(elem);
|
wasm_runtime_free(elem);
|
||||||
elem = next;
|
elem = next;
|
||||||
}
|
}
|
||||||
|
if (symbol_list->hash_table) {
|
||||||
|
AOTSymbolHashEntry **ht =
|
||||||
|
(AOTSymbolHashEntry **)symbol_list->hash_table;
|
||||||
|
uint32 i;
|
||||||
|
for (i = 0; i < SYMBOL_HASH_SIZE; i++) {
|
||||||
|
AOTSymbolHashEntry *entry = ht[i];
|
||||||
|
while (entry) {
|
||||||
|
AOTSymbolHashEntry *next = entry->hash_next;
|
||||||
|
wasm_runtime_free(entry);
|
||||||
|
entry = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wasm_runtime_free(ht);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user