mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-21 23:12:01 -07:00
test case for relocation to undefined section with base relocations
This commit is contained in:
committed by
Ryan Fleury
parent
f25dc5cc8d
commit
bd830a6023
+63
-19
@@ -40,6 +40,7 @@
|
||||
#include "linker/lnk_cmd_line.h"
|
||||
#include "linker/lnk_cmd_line.c"
|
||||
#include "linker/lnk_error.h"
|
||||
#include "linker/lnk_image_section_flags.h"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@@ -295,19 +296,19 @@ typedef enum
|
||||
internal COFF_ObjSection *
|
||||
t_push_text_section(COFF_ObjWriter *obj_writer, String8 data)
|
||||
{
|
||||
return coff_obj_writer_push_section(obj_writer, str8_lit(".text"), COFF_SectionFlag_CntCode|COFF_SectionFlag_MemRead|COFF_SectionFlag_MemExecute|COFF_SectionFlag_Align1Bytes, data);
|
||||
return coff_obj_writer_push_section(obj_writer, str8_lit(".text"), LNK_TEXT_SECTION_FLAGS, data);
|
||||
}
|
||||
|
||||
internal COFF_ObjSection *
|
||||
t_push_data_section(COFF_ObjWriter *obj_writer, String8 data)
|
||||
{
|
||||
return coff_obj_writer_push_section(obj_writer, str8_lit(".data"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead|COFF_SectionFlag_MemWrite|COFF_SectionFlag_Align1Bytes, data);
|
||||
return coff_obj_writer_push_section(obj_writer, str8_lit(".data"), LNK_DATA_SECTION_FLAGS, data);
|
||||
}
|
||||
|
||||
internal COFF_ObjSection *
|
||||
t_push_rdata_section(COFF_ObjWriter *obj_writer, String8 data)
|
||||
{
|
||||
return coff_obj_writer_push_section(obj_writer, str8_lit(".rdata"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead|COFF_SectionFlag_Align1Bytes, data);
|
||||
return coff_obj_writer_push_section(obj_writer, str8_lit(".rdata"), LNK_RDATA_SECTION_FLAGS, data);
|
||||
}
|
||||
|
||||
internal T_Result
|
||||
@@ -837,12 +838,12 @@ t_undef_section(void)
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0, COFF_MachineType_X64);
|
||||
|
||||
U8 data[] = { 0, 0, 0, 0 };
|
||||
COFF_ObjSection *data_section = coff_obj_writer_push_section(obj_writer, str8_lit(".data"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead|COFF_SectionFlag_MemWrite, str8_array_fixed(data));
|
||||
COFF_ObjSection *data_section = t_push_data_section(obj_writer, str8_array_fixed(data));
|
||||
COFF_ObjSymbol *foo = coff_obj_writer_push_symbol_undef_section(obj_writer, str8_lit(".mysect"), COFF_SectionFlag_CntInitializedData|COFF_SectionFlag_MemRead);
|
||||
coff_obj_writer_section_push_reloc(obj_writer, data_section, 0, foo, COFF_Reloc_X64_Addr32Nb);
|
||||
|
||||
U8 text[] = { 0xC3 };
|
||||
COFF_ObjSection *text_section = coff_obj_writer_push_section(obj_writer, str8_lit(".text"), COFF_SectionFlag_CntCode|COFF_SectionFlag_MemRead|COFF_SectionFlag_MemExecute, str8_array_fixed(text));
|
||||
COFF_ObjSection *text_section = t_push_text_section(obj_writer, str8_array_fixed(text));
|
||||
coff_obj_writer_push_symbol_extern(obj_writer, str8_lit("my_entry"), 0, text_section);
|
||||
|
||||
main_obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
@@ -880,6 +881,48 @@ t_undef_section(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
internal T_Result
|
||||
t_undef_reloc_section(void)
|
||||
{
|
||||
Temp scratch = scratch_begin(0,0);
|
||||
T_Result result = T_Result_Fail;
|
||||
|
||||
String8 main_obj;
|
||||
{
|
||||
COFF_ObjWriter *obj_writer = coff_obj_writer_alloc(0, COFF_MachineType_X64);
|
||||
|
||||
U8 data[] = { 0, 0, 0, 0 };
|
||||
COFF_ObjSection *data_section = t_push_data_section(obj_writer, str8_array_fixed(data));
|
||||
COFF_ObjSymbol *foo = coff_obj_writer_push_symbol_undef_section(obj_writer, str8_lit(".reloc"), LNK_RELOC_SECTION_FLAGS);
|
||||
coff_obj_writer_section_push_reloc(obj_writer, data_section, 0, foo, COFF_Reloc_X64_Addr32Nb);
|
||||
|
||||
U8 text[] = { 0xC3 };
|
||||
COFF_ObjSection *text_section = coff_obj_writer_push_section(obj_writer, str8_lit(".text"), LNK_TEXT_SECTION_FLAGS, str8_array_fixed(text));
|
||||
coff_obj_writer_push_symbol_extern(obj_writer, str8_lit("my_entry"), 0, text_section);
|
||||
|
||||
main_obj = coff_obj_writer_serialize(scratch.arena, obj_writer);
|
||||
|
||||
coff_obj_writer_release(&obj_writer);
|
||||
}
|
||||
|
||||
U8 payload[] = { 1, 2, 3 };
|
||||
String8 sec_defn_obj = t_make_sec_defn_obj(scratch.arena, str8_array_fixed(payload));
|
||||
|
||||
t_write_file(str8_lit("main.obj"), main_obj);
|
||||
t_write_file(str8_lit("sec_defn.obj"), sec_defn_obj);
|
||||
|
||||
int linker_exit_code = t_invoke_linker(str8_lit("/subsystem:console /entry:my_entry /out:a.exe main.obj sec_defn.obj"));
|
||||
if (linker_exit_code == 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
result = T_Result_Pass;
|
||||
|
||||
exit:;
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal T_Result
|
||||
t_find_merged_pdata(void)
|
||||
{
|
||||
@@ -1043,7 +1086,7 @@ t_flag_conf(void)
|
||||
}
|
||||
}
|
||||
|
||||
int linker_exit_code = t_invoke_linkerf("/subsystem:console /entry:my_entry /out:a.exe data.obj conf.obj entry.obj");
|
||||
int linker_exit_code = t_invoke_linkerf("/subsystem:console /entry:my_entry /out:a.exe conf.obj entry.obj");
|
||||
if (linker_exit_code != 0) {
|
||||
goto exit;
|
||||
}
|
||||
@@ -1542,19 +1585,20 @@ entry_point(CmdLine *cmdline)
|
||||
char *label;
|
||||
T_Result (*r)(void);
|
||||
} target_array[] = {
|
||||
{ "simple_link_test", t_simple_link_test },
|
||||
{ "undef_section", t_undef_section },
|
||||
{ "abs_vs_weak", t_abs_vs_weak },
|
||||
{ "abs_vs_regular", t_abs_vs_regular },
|
||||
{ "abs_vs_common", t_abs_vs_common },
|
||||
{ "undef_weak", t_undef_weak },
|
||||
{ "weak_cycle", t_weak_cycle },
|
||||
{ "weak_tag", t_weak_tag },
|
||||
{ "find_merged_pdata", t_find_merged_pdata },
|
||||
{ "section_sort", t_section_sort },
|
||||
{ "flag_conf", t_flag_conf },
|
||||
{ "invalid_bss", t_invalid_bss },
|
||||
{ "common_block", t_common_block },
|
||||
{ "simple_link_test", t_simple_link_test },
|
||||
{ "undef_section", t_undef_section },
|
||||
{ "undef_reloc_section", t_undef_reloc_section },
|
||||
{ "abs_vs_weak", t_abs_vs_weak },
|
||||
{ "abs_vs_regular", t_abs_vs_regular },
|
||||
{ "abs_vs_common", t_abs_vs_common },
|
||||
{ "undef_weak", t_undef_weak },
|
||||
{ "weak_cycle", t_weak_cycle },
|
||||
{ "weak_tag", t_weak_tag },
|
||||
{ "find_merged_pdata", t_find_merged_pdata },
|
||||
{ "section_sort", t_section_sort },
|
||||
{ "flag_conf", t_flag_conf },
|
||||
{ "invalid_bss", t_invalid_bss },
|
||||
{ "common_block", t_common_block },
|
||||
//{ "base_relocs", t_base_relocs },
|
||||
{ "simple_lib_test", t_simple_lib_test },
|
||||
{ "import_export", t_import_export },
|
||||
|
||||
Reference in New Issue
Block a user