This commit is contained in:
jammar1 2026-04-17 07:43:44 -07:00 committed by GitHub
commit b2965c5d13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(
while (sym) { sizeof(AOTSymbolHashEntry *) * SYMBOL_HASH_SIZE);
if (!strcmp(sym->symbol, symbol_name)) { if (symbol_list->hash_table)
if (is_new) memset(symbol_list->hash_table, 0,
*is_new = false; sizeof(AOTSymbolHashEntry *) * SYMBOL_HASH_SIZE);
return index; }
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;
} }
sym = sym->next;
index++;
}
/* Not found in symbol_list, add it */
sym = wasm_runtime_malloc(sizeof(AOTSymbolNode));
if (!sym) {
return (uint32)-1;
}
memset(sym, 0, sizeof(AOTSymbolNode));
sym->symbol = (char *)symbol_name;
sym->str_len = (uint32)strlen(symbol_name);
if (!symbol_list->head) {
symbol_list->head = symbol_list->end = sym;
} }
else { else {
symbol_list->end->next = sym; AOTSymbolNode *sym = symbol_list->head;
symbol_list->end = sym; uint32 idx = 0;
while (sym) {
if (!strcmp(sym->symbol, symbol_name)) {
if (is_new)
*is_new = false;
return idx;
}
sym = sym->next;
idx++;
}
}
index = symbol_list->len;
{
AOTSymbolNode *sym = wasm_runtime_malloc(sizeof(AOTSymbolNode));
if (!sym)
return (uint32)-1;
memset(sym, 0, sizeof(AOTSymbolNode));
sym->symbol = (char *)symbol_name;
sym->str_len = (uint32)strlen(symbol_name);
if (!symbol_list->head)
symbol_list->head = symbol_list->end = sym;
else {
symbol_list->end->next = sym;
symbol_list->end = sym;
}
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;
} }
symbol_list->len++;
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