mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-01 03:40:02 +00:00
simplifying symbol table scopes
Linker cannot register extern import symbols initially because the import object files are not available until all other object files are resolved. To work around this, we create a stub weak symbol and assign it to each import symbol. This allows linker to proceed. Once the import object files are generated, linker replaces the stub symbol with the actual ones from the import objects.
This commit is contained in:
committed by
Ryan Fleury
parent
dd715dacf7
commit
d3dedd8bef
+12
-13
@@ -462,6 +462,12 @@ lnk_make_null_obj(Arena *arena)
|
||||
{
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0,COFF_MachineType_Unknown);
|
||||
|
||||
// make import stub
|
||||
{
|
||||
COFF_ObjSymbol *tag = coff_obj_writer_push_symbol_abs(obj_writer, str8_lit("RAD_IMPORT_STUB_NULL"), 0, COFF_SymStorageClass_Static);
|
||||
coff_obj_writer_push_symbol_weak(obj_writer, str8_lit(LNK_IMPORT_STUB), COFF_WeakExt_AntiDependency, tag);
|
||||
}
|
||||
|
||||
// push .debug$T sections with null leaf
|
||||
String8 null_debug_data;
|
||||
{
|
||||
@@ -1026,10 +1032,6 @@ THREAD_POOL_TASK_FUNC(lnk_undef_symbol_finder)
|
||||
if (has_defn) {
|
||||
continue;
|
||||
}
|
||||
LNK_Symbol *has_import = lnk_symbol_table_search(task->symtab, LNK_SymbolScope_Import, symbol->name);
|
||||
if (has_import) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LNK_Symbol *member_symbol = lnk_symbol_table_search(task->symtab, LNK_SymbolScope_Lib, symbol->name);
|
||||
if (member_symbol) {
|
||||
@@ -1059,10 +1061,6 @@ THREAD_POOL_TASK_FUNC(lnk_weak_symbol_finder)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
LNK_Symbol *has_import = lnk_symbol_table_search(task->symtab, LNK_SymbolScope_Import, symbol->name);
|
||||
if (has_import) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LNK_Symbol *member_symbol = 0;
|
||||
{
|
||||
@@ -1296,15 +1294,16 @@ lnk_build_link_context(TP_Context *tp, TP_Arena *tp_arena, LNK_Config *config)
|
||||
}
|
||||
|
||||
// was import already created?
|
||||
if (lnk_symbol_table_search(symtab, LNK_SymbolScope_Import, import_header.func_name)) {
|
||||
if (lnk_symbol_table_search(symtab, LNK_SymbolScope_Defined, import_header.func_name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// create import stubs (later replaced with acutal imports generated by linker)
|
||||
LNK_Symbol *thunk_symbol = lnk_make_import_symbol(scratch.arena, import_header.func_name, input->data.coff_import);
|
||||
LNK_Symbol *imp_symbol = lnk_make_import_symbol(scratch.arena, push_str8f(scratch.arena, "__imp_%S", import_header.func_name), input->data.coff_import);
|
||||
lnk_symbol_table_push(symtab, LNK_SymbolScope_Import, thunk_symbol);
|
||||
lnk_symbol_table_push(symtab, LNK_SymbolScope_Import, imp_symbol);
|
||||
LNK_Symbol *import_stub = lnk_symbol_table_search(symtab, LNK_SymbolScope_Defined, str8_lit(LNK_IMPORT_STUB));
|
||||
LNK_Symbol *thunk_symbol = lnk_make_defined_symbol(scratch.arena, import_header.func_name, import_stub->u.defined.obj, import_stub->u.defined.symbol_idx);
|
||||
LNK_Symbol *imp_symbol = lnk_make_defined_symbol(scratch.arena, push_str8f(scratch.arena, "__imp_%S", import_header.func_name), import_stub->u.defined.obj, import_stub->u.defined.symbol_idx);
|
||||
lnk_symbol_table_push(symtab, LNK_SymbolScope_Defined, thunk_symbol);
|
||||
lnk_symbol_table_push(symtab, LNK_SymbolScope_Defined, imp_symbol);
|
||||
|
||||
// pick imports hash table
|
||||
HashTable *imports_ht;
|
||||
|
||||
Reference in New Issue
Block a user