more validity checks in simple_link_test

This commit is contained in:
Nikita Smith
2025-06-25 10:53:24 -07:00
committed by Ryan Fleury
parent c4a36f73dc
commit fe967a3d36
+11 -4
View File
@@ -614,7 +614,10 @@ t_simple_link_test(void)
int virt_align = 4096; int virt_align = 4096;
String8 out_name = str8_lit("a.exe"); String8 out_name = str8_lit("a.exe");
int linker_exit_code = t_invoke_linkerf("/entry:my_entry /subsystem:console /fixed /filealign:%d /align:%d /out:%S %S", file_align, virt_align, out_name, main_obj_name); int linker_exit_code = t_invoke_linkerf("/entry:my_entry /subsystem:console /fixed /filealign:%d /align:%d /out:%S %S", file_align, virt_align, out_name, main_obj_name);
if (linker_exit_code == 0) { if (linker_exit_code != 0) {
goto exit;
}
String8 exe = t_read_file(scratch.arena, out_name); String8 exe = t_read_file(scratch.arena, out_name);
PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, 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; COFF_SectionHeader *section_table = (COFF_SectionHeader *)str8_substr(exe, pe.section_table_range).str;
@@ -623,7 +626,7 @@ t_simple_link_test(void)
if (pe.is_pe32) { if (pe.is_pe32) {
goto exit; goto exit;
} }
if (pe.section_count == 0) { if (pe.section_count != 1) {
goto exit; goto exit;
} }
if (pe.arch != Arch_x64) { if (pe.arch != Arch_x64) {
@@ -641,6 +644,9 @@ t_simple_link_test(void)
if (pe.symbol_count != 0) { if (pe.symbol_count != 0) {
goto exit; goto exit;
} }
if (pe.data_dir_count != PE_DataDirectoryIndex_COUNT) {
goto exit;
}
// check section alignment // check section alignment
for (U64 sect_idx = 0; sect_idx < pe.section_count; sect_idx += 1) { for (U64 sect_idx = 0; sect_idx < pe.section_count; sect_idx += 1) {
@@ -660,6 +666,9 @@ t_simple_link_test(void)
if (text_section->foff != file_align) { if (text_section->foff != file_align) {
goto exit; goto exit;
} }
if (pe.entry_point != text_section->voff) {
goto exit;
}
String8 text_data = str8_substr(exe, rng_1u64(text_section->foff, text_section->foff + text_section->vsize)); String8 text_data = str8_substr(exe, rng_1u64(text_section->foff, text_section->foff + text_section->vsize));
if (!str8_match(text_data, str8_array_fixed(text_payload), 0)) { if (!str8_match(text_data, str8_array_fixed(text_payload), 0)) {
@@ -667,8 +676,6 @@ t_simple_link_test(void)
} }
result = T_Result_Pass; result = T_Result_Pass;
}
exit:; exit:;
scratch_end(scratch); scratch_end(scratch);
return result; return result;