mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-17 17:42:22 -07:00
add a relocation to "a" to prevent linker from removing .test
This commit is contained in:
committed by
Ryan Fleury
parent
17d35cd327
commit
ffc9317067
+21
-4
@@ -2348,18 +2348,34 @@ t_comdat_no_duplicates(void)
|
||||
Temp scratch = scratch_begin(0,0);
|
||||
T_Result result = T_Result_Fail;
|
||||
|
||||
String8 test_obj;
|
||||
{
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0, COFF_MachineType_X64);
|
||||
COFF_ObjSection *test_sect = coff_obj_writer_push_section(obj_writer, str8_lit(".test"), PE_DATA_SECTION_FLAGS|COFF_SectionFlag_LnkCOMDAT|COFF_SectionFlag_Align1Bytes, str8_lit("a"));
|
||||
coff_obj_writer_push_symbol_secdef(obj_writer, test_sect, COFF_ComdatSelect_NoDuplicates);
|
||||
coff_obj_writer_push_symbol_extern(obj_writer, str8_lit("a"), 0, test_sect);
|
||||
String8 obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
test_obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
if (!t_write_file(str8_lit("a.obj"), obj)) { goto exit; }
|
||||
if (!t_write_file(str8_lit("b.obj"), obj)) { goto exit; }
|
||||
}
|
||||
|
||||
t_write_entry_obj();
|
||||
String8 entry_obj;
|
||||
{
|
||||
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_obj_writer_push_symbol_extern(obj_writer, str8_lit("entry"), 0, sect);
|
||||
COFF_ObjSymbol *symbol = coff_obj_writer_push_symbol_undef(obj_writer, str8_lit("a"));
|
||||
coff_obj_writer_section_push_reloc_voff(obj_writer, sect, 0, symbol);
|
||||
entry_obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
}
|
||||
|
||||
if (!t_write_file(str8_lit("a.obj"), test_obj)) { goto exit; }
|
||||
if (!t_write_file(str8_lit("b.obj"), test_obj)) { goto exit; }
|
||||
if (!t_write_file(str8_lit("entry.obj"), entry_obj)) { goto exit; }
|
||||
|
||||
int duplicates_exit_code = t_invoke_linkerf("/subsystem:console /entry:entry /out:a.exe a.obj b.obj entry.obj");
|
||||
if (duplicates_exit_code == 0) { goto exit; }
|
||||
@@ -2373,6 +2389,7 @@ t_comdat_no_duplicates(void)
|
||||
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 *sect = t_coff_section_header_from_name(exe, section_table, pe.section_count, str8_lit(".test"));
|
||||
if (!sect) { goto exit; }
|
||||
String8 data = str8_substr(exe, rng_1u64(sect->foff, sect->foff + sect->vsize));
|
||||
if (!str8_match(data, str8_lit("a"), 0)) { goto exit; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user