From c47b35f635f5756993953958b76aa9ef57a63814 Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Tue, 9 Sep 2025 16:48:27 -0700 Subject: [PATCH] update link symbol set logic to replace import address symbols with jump thunk symbols --- src/linker/lnk_lib.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/linker/lnk_lib.c b/src/linker/lnk_lib.c index 1f317a16..dc696abb 100644 --- a/src/linker/lnk_lib.c +++ b/src/linker/lnk_lib.c @@ -228,13 +228,22 @@ lnk_lib_set_link_symbol(LNK_Lib *lib, U32 member_idx, LNK_Symbol *link_symbol) { local_persist LNK_Symbol null_symbol; - LNK_Symbol *slot = ins_atomic_ptr_eval_assign(&lib->was_member_linked[member_idx], &null_symbol); - B32 is_first_set = (slot == 0); + B32 is_first_set; + + LNK_Symbol *slot = ins_atomic_ptr_eval_assign(&lib->was_member_linked[member_idx], &null_symbol); for (;;) { + is_first_set = (slot == 0); + // update slot symbol if it is empty or link symbol comes before symbol in the slot if (slot && slot != &null_symbol) { - if (lnk_symbol_is_before(slot, link_symbol)) { + if (!str8_starts_with(link_symbol->name, str8_lit("__imp_")) && str8_starts_with(slot->name, str8_lit("__imp_"))) { + // replace import address symbol with jump thunk symbol + slot = link_symbol; + is_first_set = 1; + } else if (str8_starts_with(link_symbol->name, str8_lit("__imp_")) && !str8_starts_with(slot->name, str8_lit("__imp_"))) { + // no need to replace + } else if (lnk_symbol_is_before(slot, link_symbol)) { slot = link_symbol; } } else {