mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-14 08:02:23 -07:00
test for /INCLUDE
This commit is contained in:
committed by
Ryan Fleury
parent
8d7bd6f9fe
commit
40efbeb512
@@ -2888,6 +2888,70 @@ exit:;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal T_Result
|
||||
t_include(void)
|
||||
{
|
||||
Temp scratch = scratch_begin(0,0);
|
||||
T_Result result = T_Result_Fail;
|
||||
|
||||
{
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0, COFF_MachineType_X64);
|
||||
COFF_ObjSection *sect = t_push_data_section(obj_writer, str8_lit("foo"));
|
||||
coff_obj_writer_push_symbol_extern(obj_writer, str8_lit("foo"), 0, sect);
|
||||
String8 obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
if (!t_write_file(str8_lit("include.obj"), obj)) { goto exit; }
|
||||
|
||||
COFF_LibWriter *lib_writer = coff_lib_writer_alloc();
|
||||
coff_lib_writer_push_obj(lib_writer, str8_lit("include.obj"), obj);
|
||||
String8List lib = coff_lib_writer_serialize(scratch.arena, lib_writer, 0, 0, 1);
|
||||
coff_lib_writer_release(&lib_writer);
|
||||
if (!t_write_file_list(str8_lit("include.lib"), lib)) { goto exit; }
|
||||
}
|
||||
|
||||
{
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0, COFF_MachineType_X64);
|
||||
U8 text[] = {
|
||||
0x48, 0xC7, 0xC0, 0x00, 0x00, 0x00, 0x00, // mov rax, $imm
|
||||
0xC3 // ret
|
||||
};
|
||||
COFF_ObjSection *sect = coff_obj_writer_push_section(obj_writer, str8_lit(".text"), PE_TEXT_SECTION_FLAGS, str8_array_fixed(text));
|
||||
COFF_ObjSymbol *symbol = coff_obj_writer_push_symbol_extern(obj_writer, str8_lit("entry"), 0, sect);
|
||||
coff_obj_writer_section_push_reloc_voff(obj_writer, sect, 0, symbol);
|
||||
String8 obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
if (!t_write_file(str8_lit("entry.obj"), obj)) { goto exit; }
|
||||
}
|
||||
|
||||
int linker_exit_code;
|
||||
|
||||
// simple include test
|
||||
linker_exit_code = t_invoke_linkerf("/subsystem:console /entry:entry /out:a.exe /include:foo entry.obj include.lib");
|
||||
if (linker_exit_code != 0) { goto exit; }
|
||||
|
||||
// validate that linker pulled-in include.obj
|
||||
{
|
||||
String8 exe = t_read_file(scratch.arena, str8_lit("a.exe"));
|
||||
PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, exe);
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)str8_substr(exe, pe.section_table_range).str;
|
||||
String8 string_table = str8_substr(exe, pe.string_table_range);
|
||||
COFF_SectionHeader *foo_sect = t_coff_section_header_from_name(string_table, section_table, pe.section_count, str8_lit(".data"));
|
||||
if (foo_sect == 0) { goto exit; }
|
||||
String8 foo_data = str8_substr(exe, rng_1u64(foo_sect->foff, foo_sect->foff + foo_sect->vsize));
|
||||
if (!str8_match(foo_data, str8_lit("foo"), 0)) { goto exit; }
|
||||
}
|
||||
|
||||
// test unresolved include
|
||||
linker_exit_code = t_invoke_linkerf("/subsystem:console /entry:entry /out:a.exe /include:ewq entry.obj");
|
||||
if (linker_exit_code == 0) { goto exit; }
|
||||
if (t_ident_linker() == T_Linker_RAD && linker_exit_code != LNK_Error_UnresolvedSymbol) { goto exit; }
|
||||
|
||||
result = T_Result_Pass;
|
||||
exit:;
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
internal void
|
||||
@@ -2934,6 +2998,7 @@ entry_point(CmdLine *cmdline)
|
||||
{ "comdat_associative_non_comdat", t_comdat_associative_non_comdat },
|
||||
{ "comdat_associative_out_of_bounds", t_comdat_associative_out_of_bounds },
|
||||
{ "alt_name", t_alt_name },
|
||||
{ "include", t_include },
|
||||
//{ "import_export", t_import_export },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user