mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-05 05:18:40 +00:00
make export table with COFF obj writer,
partially converted import table to COFF obj writer
This commit is contained in:
committed by
Ryan Fleury
parent
3a2bb318c7
commit
19a7ada1dc
@@ -536,145 +536,6 @@ lnk_build_lib(Arena *arena, COFF_MachineType machine, COFF_TimeStamp time_stamp,
|
||||
return lib;
|
||||
}
|
||||
|
||||
internal String8
|
||||
lnk_build_import_entry_obj(Arena *arena, String8 dll_name, COFF_TimeStamp time_stamp, COFF_MachineType machine)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
Assert(machine == COFF_MachineType_X64);
|
||||
Assert(str8_match_lit("dll", str8_skip_last_dot(dll_name), StringMatchFlag_CaseInsensitive|StringMatchFlag_RightSideSloppy));
|
||||
|
||||
String8 dll_name_no_ext = str8_chop_last_dot(dll_name);
|
||||
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(time_stamp, machine);
|
||||
|
||||
String8 debug_symbols;
|
||||
{
|
||||
CV_SymbolList symbol_list = { .signature = CV_Signature_C13 };
|
||||
String8 comp3_data = lnk_make_linker_compile3(scratch.arena, machine);
|
||||
cv_symbol_list_push_data(scratch.arena, &symbol_list, CV_SymKind_COMPILE3, comp3_data);
|
||||
debug_symbols = lnk_make_debug_s(obj_writer->arena, symbol_list);
|
||||
}
|
||||
|
||||
String8 dll_name_cstr = push_cstr(obj_writer->arena, dll_name);
|
||||
COFF_ObjSection *debugs = coff_obj_writer_push_section(obj_writer, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS|COFF_SectionFlag_Align1Bytes, debug_symbols);
|
||||
COFF_ObjSection *idata2 = coff_obj_writer_push_section(obj_writer, str8_lit(".idata$2"), LNK_DATA_SECTION_FLAGS|COFF_SectionFlag_Align4Bytes, str8_zero());
|
||||
COFF_ObjSection *idata6 = coff_obj_writer_push_section(obj_writer, str8_lit(".idata$6"), LNK_DATA_SECTION_FLAGS|COFF_SectionFlag_Align2Bytes, dll_name_cstr);
|
||||
|
||||
coff_obj_writer_push_symbol_abs(obj_writer, str8_lit("@comp.id"), 0x1018175, COFF_SymStorageClass_Static);
|
||||
{
|
||||
String8 symbol_name = push_str8f(arena, "__IMPORT_DESCRIPTOR_%S", dll_name_no_ext);
|
||||
coff_obj_writer_push_symbol_external(obj_writer, symbol_name, 0, idata2);
|
||||
}
|
||||
COFF_ObjSymbol *idata2_symbol = coff_obj_writer_push_symbol_sect(obj_writer, idata2->name, idata2);
|
||||
COFF_ObjSymbol *idata6_symbol = coff_obj_writer_push_symbol_static(obj_writer, idata6->name, 0, idata6);
|
||||
COFF_ObjSymbol *idata4_symbol = coff_obj_writer_push_symbol_undef_sect(obj_writer, str8_lit(".idata$4"), COFF_SectionFlag_MemWrite|COFF_SectionFlag_MemRead|COFF_SectionFlag_CntInitializedData);
|
||||
COFF_ObjSymbol *idata5_symbol = coff_obj_writer_push_symbol_undef_sect(obj_writer, str8_lit(".idata$5"), COFF_SectionFlag_MemWrite|COFF_SectionFlag_MemRead|COFF_SectionFlag_CntInitializedData);
|
||||
coff_obj_writer_push_symbol_undef(obj_writer, str8_lit("__NULL_IMPORT_DESCRIPTOR"));
|
||||
{
|
||||
String8 symbol_name = push_str8f(arena, "\x7f%S_NULL_THUNK_DATA", dll_name_no_ext);
|
||||
coff_obj_writer_push_symbol_undef(obj_writer, symbol_name);
|
||||
}
|
||||
|
||||
{
|
||||
PE_ImportEntry *import_entry = push_array(obj_writer->arena, PE_ImportEntry, 1);
|
||||
str8_list_push(obj_writer->arena, &idata2->data, str8_struct(import_entry));
|
||||
coff_obj_writer_section_push_reloc(obj_writer, idata2, OffsetOf(PE_ImportEntry, name_voff), idata6_symbol, COFF_Reloc_X64_Addr32Nb);
|
||||
coff_obj_writer_section_push_reloc(obj_writer, idata2, OffsetOf(PE_ImportEntry, lookup_table_voff), idata4_symbol, COFF_Reloc_X64_Addr32Nb);
|
||||
coff_obj_writer_section_push_reloc(obj_writer, idata2, OffsetOf(PE_ImportEntry, import_addr_table_voff), idata5_symbol, COFF_Reloc_X64_Addr32Nb);
|
||||
}
|
||||
|
||||
String8 obj = coff_obj_writer_serialize(arena, obj_writer);
|
||||
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
|
||||
scratch_end(scratch);
|
||||
ProfEnd();
|
||||
return obj;
|
||||
}
|
||||
|
||||
internal String8
|
||||
lnk_build_null_import_descriptor_obj(Arena *arena, COFF_TimeStamp time_stamp, COFF_MachineType machine)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(time_stamp, machine);
|
||||
|
||||
String8 debug_symbols;
|
||||
{
|
||||
CV_SymbolList symbol_list = { .signature = CV_Signature_C13 };
|
||||
String8 comp3_data = lnk_make_linker_compile3(scratch.arena, machine);
|
||||
cv_symbol_list_push_data(scratch.arena, &symbol_list, CV_SymKind_COMPILE3, comp3_data);
|
||||
debug_symbols = lnk_make_debug_s(obj_writer->arena, symbol_list);
|
||||
}
|
||||
|
||||
PE_ImportEntry *import_desc = push_array(obj_writer->arena, PE_ImportEntry, 1);
|
||||
COFF_ObjSection *debugs = coff_obj_writer_push_section(obj_writer, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS|COFF_SectionFlag_Align1Bytes, debug_symbols);
|
||||
COFF_ObjSection *idata3 = coff_obj_writer_push_section(obj_writer, str8_lit(".idata$3"), LNK_DATA_SECTION_FLAGS|COFF_SectionFlag_Align4Bytes, str8_struct(import_desc));
|
||||
|
||||
coff_obj_writer_push_symbol_abs(obj_writer, str8_lit("@comp.id"), 0x01018175, COFF_SymStorageClass_Static);
|
||||
coff_obj_writer_push_symbol_external(obj_writer, str8_lit("__NULL_IMPORT_DESCRIPTOR"), 0, idata3);
|
||||
|
||||
String8 obj = coff_obj_writer_serialize(arena, obj_writer);
|
||||
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
|
||||
scratch_end(scratch);
|
||||
ProfEnd();
|
||||
return obj;
|
||||
}
|
||||
|
||||
internal String8
|
||||
lnk_build_null_thunk_data_obj(Arena *arena, String8 dll_name, COFF_TimeStamp time_stamp, COFF_MachineType machine)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
Assert(str8_match_lit("dll", str8_skip_last_dot(dll_name), StringMatchFlag_CaseInsensitive|StringMatchFlag_RightSideSloppy));
|
||||
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(time_stamp, machine);
|
||||
|
||||
String8 debug_symbols;
|
||||
{
|
||||
CV_SymbolList symbol_list = { .signature = CV_Signature_C13 };
|
||||
String8 comp3_data = lnk_make_linker_compile3(scratch.arena, machine);
|
||||
cv_symbol_list_push_data(scratch.arena, &symbol_list, CV_SymKind_COMPILE3, comp3_data);
|
||||
debug_symbols = lnk_make_debug_s(obj_writer->arena, symbol_list);
|
||||
}
|
||||
|
||||
COFF_ObjSection *debugs = coff_obj_writer_push_section(obj_writer, str8_lit(".debug$S"), LNK_DEBUG_SECTION_FLAGS|COFF_SectionFlag_Align1Bytes, debug_symbols);
|
||||
COFF_ObjSection *idata4 = coff_obj_writer_push_section(obj_writer, str8_lit(".idata$4"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead|COFF_SectionFlag_MemWrite, str8_zero());
|
||||
COFF_ObjSection *idata5 = coff_obj_writer_push_section(obj_writer, str8_lit(".idata$5"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead|COFF_SectionFlag_MemWrite, str8_zero());
|
||||
|
||||
U64 import_size = coff_word_size_from_machine(machine);
|
||||
|
||||
U8 *null_thunk = push_array(obj_writer->arena, U8, import_size);
|
||||
U8 *null_lookup = push_array(obj_writer->arena, U8, import_size);
|
||||
|
||||
str8_list_push(obj_writer->arena, &idata5->data, str8_array(null_thunk, import_size));
|
||||
str8_list_push(obj_writer->arena, &idata4->data, str8_array(null_lookup, import_size));
|
||||
|
||||
idata4->flags |= coff_section_flag_from_align_size(import_size);
|
||||
idata5->flags |= coff_section_flag_from_align_size(import_size);
|
||||
|
||||
coff_obj_writer_push_symbol_abs(obj_writer, str8_lit("@comp.id"), 0x1018175, COFF_SymStorageClass_Static);
|
||||
{
|
||||
String8 dll_name_no_ext = str8_chop_last_dot(dll_name);
|
||||
String8 symbol_name = push_str8f(arena, "\x7f%S_NULL_THUNK_DATA", dll_name_no_ext);
|
||||
coff_obj_writer_push_symbol_external(obj_writer, symbol_name, 0, idata5);
|
||||
}
|
||||
|
||||
String8 obj = coff_obj_writer_serialize(arena, obj_writer);
|
||||
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
|
||||
scratch_end(scratch);
|
||||
ProfEnd();
|
||||
return obj;
|
||||
}
|
||||
|
||||
internal String8
|
||||
lnk_build_lib_member_header(Arena *arena, String8 name, COFF_TimeStamp time_stamp, U16 user_id, U16 group_id, U16 mode, U32 size)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user