mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-13 07:32:23 -07:00
went over COFF string table and changed the parser code accept to String8
This commit is contained in:
+6
-8
@@ -52,14 +52,13 @@ coff_section_flag_from_align_size(U64 align)
|
||||
}
|
||||
|
||||
internal String8
|
||||
coff_name_from_section_header(String8 raw_coff, COFF_SectionHeader *header, U64 string_table_off)
|
||||
coff_name_from_section_header(String8 string_table, COFF_SectionHeader *header)
|
||||
{
|
||||
String8 name = str8_cstring_capped(header->name, header->name + sizeof(header->name));
|
||||
if (name.str[0] == '/') {
|
||||
String8 ascii_off = str8_skip(name, 1);
|
||||
U64 name_rel_off = u64_from_str8(ascii_off, 10);
|
||||
U64 name_off = name_rel_off + string_table_off;
|
||||
name = str8_cstring_capped(raw_coff.str + name_off, raw_coff.str + raw_coff.size);
|
||||
String8 name_off_str = str8_skip(name, 1);
|
||||
U64 name_off = u64_from_str8(name_off_str, 10);
|
||||
name = str8_cstring_capped(string_table.str + name_off, string_table.str+string_table.size);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@@ -94,12 +93,11 @@ coff_parse_section_name(String8 full_name, String8 *name_out, String8 *postfix_o
|
||||
}
|
||||
|
||||
internal String8
|
||||
coff_read_symbol_name(String8 raw_coff, U64 string_table_off, COFF_SymbolName *name)
|
||||
coff_read_symbol_name(String8 string_table, COFF_SymbolName *name)
|
||||
{
|
||||
String8 name_str = str8_lit("");
|
||||
if (name->long_name.zeroes == 0) {
|
||||
U64 name_string_off = string_table_off + name->long_name.string_table_offset;
|
||||
str8_deserial_read_cstr(raw_coff, name_string_off, &name_str);
|
||||
str8_deserial_read_cstr(string_table, name->long_name.string_table_offset, &name_str);
|
||||
} else {
|
||||
U32 i;
|
||||
for (i = 0; i < sizeof(name->short_name); ++i) {
|
||||
|
||||
+2
-2
@@ -567,13 +567,13 @@ typedef struct COFF_ImportHeader
|
||||
internal U64 coff_align_size_from_section_flags(COFF_SectionFlags flags);
|
||||
internal COFF_SectionFlags coff_section_flag_from_align_size (U64 align);
|
||||
|
||||
internal String8 coff_name_from_section_header(String8 raw_coff, COFF_SectionHeader *header, U64 string_table_off);
|
||||
internal String8 coff_name_from_section_header(String8 string_table, COFF_SectionHeader *header);
|
||||
internal void coff_parse_section_name (String8 full_name, String8 *name_out, String8 *postfix_out);
|
||||
|
||||
////////////////////////////////
|
||||
// Symbol
|
||||
|
||||
internal String8 coff_read_symbol_name(String8 raw_coff, U64 string_table_off, COFF_SymbolName *name);
|
||||
internal String8 coff_read_symbol_name(String8 string_table, COFF_SymbolName *name);
|
||||
|
||||
////////////////////////////////
|
||||
// Reloc
|
||||
|
||||
+14
-14
@@ -99,33 +99,33 @@ coff_file_header_info_from_data(String8 raw_coff)
|
||||
COFF_BigObjHeader *header32 = (COFF_BigObjHeader*)raw_coff.str;
|
||||
info.is_big_obj = 1;
|
||||
info.machine = header32->machine;
|
||||
info.header_size = sizeof(COFF_BigObjHeader);
|
||||
info.section_array_off = sizeof(COFF_BigObjHeader);
|
||||
info.section_count_no_null = header32->section_count;
|
||||
info.string_table_off = header32->symbol_table_foff + sizeof(COFF_Symbol32) * header32->symbol_count;
|
||||
info.symbol_size = sizeof(COFF_Symbol32);
|
||||
info.symbol_off = header32->symbol_table_foff;
|
||||
info.symbol_count = header32->symbol_count;
|
||||
info.symbol_size = sizeof(COFF_Symbol32);
|
||||
info.header_range = rng_1u64(0, sizeof(COFF_BigObjHeader));
|
||||
info.section_table_range = rng_1u64(info.header_range.max, info.header_range.max + sizeof(COFF_SectionHeader) * header32->section_count);
|
||||
info.symbol_table_range = rng_1u64(header32->symbol_table_foff, header32->symbol_table_foff + sizeof(COFF_Symbol32) * header32->symbol_count);
|
||||
info.string_table_range = rng_1u64(info.symbol_table_range.max, raw_coff.size);
|
||||
} else if (coff_is_obj(raw_coff)) {
|
||||
COFF_FileHeader *header16 = (COFF_FileHeader*)raw_coff.str;
|
||||
info.is_big_obj = 0;
|
||||
info.machine = header16->machine;
|
||||
info.header_size = sizeof(COFF_FileHeader);
|
||||
info.section_array_off = sizeof(COFF_FileHeader);
|
||||
info.section_count_no_null = header16->section_count;
|
||||
info.string_table_off = header16->symbol_table_foff + sizeof(COFF_Symbol16) * header16->symbol_count;
|
||||
info.symbol_size = sizeof(COFF_Symbol16);
|
||||
info.symbol_off = header16->symbol_table_foff;
|
||||
info.symbol_count = header16->symbol_count;
|
||||
info.symbol_size = sizeof(COFF_Symbol16);
|
||||
info.header_range = rng_1u64(0, sizeof(COFF_FileHeader));
|
||||
info.section_table_range = rng_1u64(info.header_range.max, info.header_range.max + sizeof(COFF_SectionHeader) * header16->section_count);
|
||||
info.symbol_table_range = rng_1u64(header16->symbol_table_foff, header16->symbol_table_foff + sizeof(COFF_Symbol16) * header16->symbol_count);
|
||||
info.string_table_range = rng_1u64(info.symbol_table_range.max, raw_coff.size);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
internal COFF_ParsedSymbol
|
||||
coff_parse_symbol32(String8 raw_coff, U64 string_table_off, COFF_Symbol32 *sym32)
|
||||
coff_parse_symbol32(String8 string_table, COFF_Symbol32 *sym32)
|
||||
{
|
||||
COFF_ParsedSymbol result = {0};
|
||||
result.name = coff_read_symbol_name(raw_coff, string_table_off, &sym32->name);
|
||||
result.name = coff_read_symbol_name(string_table, &sym32->name);
|
||||
result.value = sym32->value;
|
||||
result.section_number = sym32->section_number;
|
||||
result.type = sym32->type;
|
||||
@@ -135,10 +135,10 @@ coff_parse_symbol32(String8 raw_coff, U64 string_table_off, COFF_Symbol32 *sym32
|
||||
}
|
||||
|
||||
internal COFF_ParsedSymbol
|
||||
coff_parse_symbol16(String8 raw_coff, U64 string_table_off, COFF_Symbol16 *sym16)
|
||||
coff_parse_symbol16(String8 string_table, COFF_Symbol16 *sym16)
|
||||
{
|
||||
COFF_ParsedSymbol result = {0};
|
||||
result.name = coff_read_symbol_name(raw_coff, string_table_off, &sym16->name);
|
||||
result.name = coff_read_symbol_name(string_table, &sym16->name);
|
||||
result.value = sym16->value;
|
||||
if (sym16->section_number == COFF_Symbol_DebugSection16) {
|
||||
result.section_number = COFF_Symbol_DebugSection32;
|
||||
|
||||
@@ -9,12 +9,13 @@ typedef struct COFF_FileHeaderInfo
|
||||
B32 is_big_obj;
|
||||
COFF_MachineType machine;
|
||||
U64 header_size;
|
||||
U64 section_array_off;
|
||||
U64 section_count_no_null;
|
||||
U64 string_table_off;
|
||||
U64 symbol_size;
|
||||
U64 symbol_off;
|
||||
U64 symbol_count;
|
||||
Rng1U64 header_range;
|
||||
Rng1U64 section_table_range;
|
||||
Rng1U64 symbol_table_range;
|
||||
Rng1U64 string_table_range;
|
||||
} COFF_FileHeaderInfo;
|
||||
|
||||
////////////////////////////////
|
||||
@@ -249,8 +250,8 @@ internal COFF_FileHeaderInfo coff_file_header_info_from_data(String8 raw_coff);
|
||||
////////////////////////////////
|
||||
// Symbol
|
||||
|
||||
internal COFF_ParsedSymbol coff_parse_symbol32(String8 raw_coff, U64 string_table_off, COFF_Symbol32 *sym32);
|
||||
internal COFF_ParsedSymbol coff_parse_symbol16(String8 raw_coff, U64 string_table_off, COFF_Symbol16 *sym16);
|
||||
internal COFF_ParsedSymbol coff_parse_symbol32(String8 string_table, COFF_Symbol32 *sym32);
|
||||
internal COFF_ParsedSymbol coff_parse_symbol16(String8 string_table, COFF_Symbol16 *sym16);
|
||||
|
||||
internal COFF_Symbol32Array coff_symbol_array_from_data_16(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count);
|
||||
internal COFF_Symbol32Array coff_symbol_array_from_data_32(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count);
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
|
||||
internal B32
|
||||
dw_is_dwarf_present_coff_section_table(String8 raw_image,
|
||||
U64 string_table_off,
|
||||
String8 string_table,
|
||||
U64 section_count,
|
||||
COFF_SectionHeader *sections)
|
||||
COFF_SectionHeader *section_table)
|
||||
{
|
||||
B32 is_dwarf_present = 0;
|
||||
|
||||
for (U64 i = 0; i < section_count; ++i) {
|
||||
COFF_SectionHeader *header = §ions[i];
|
||||
String8 name = coff_name_from_section_header(raw_image, header, string_table_off);
|
||||
COFF_SectionHeader *header = §ion_table[i];
|
||||
String8 name = coff_name_from_section_header(string_table, header);
|
||||
|
||||
DW_SectionKind s = dw_section_kind_from_string(name);
|
||||
if (s == DW_Section_Null) {
|
||||
@@ -30,17 +30,17 @@ dw_is_dwarf_present_coff_section_table(String8 raw_image,
|
||||
internal DW_Input
|
||||
dw_input_from_coff_section_table(Arena *arena,
|
||||
String8 raw_image,
|
||||
U64 string_table_off,
|
||||
String8 string_table,
|
||||
U64 section_count,
|
||||
COFF_SectionHeader *sections)
|
||||
COFF_SectionHeader *section_table)
|
||||
{
|
||||
DW_Input input = {0};
|
||||
B32 sect_status[ArrayCount(input.sec)] = {0};
|
||||
|
||||
for (U64 i = 0; i < section_count; ++i) {
|
||||
COFF_SectionHeader *header = §ions[i];
|
||||
COFF_SectionHeader *header = §ion_table[i];
|
||||
Rng1U64 raw_data_range = rng_1u64(header->foff, header->foff + header->fsize);
|
||||
String8 name = coff_name_from_section_header(raw_image, header, string_table_off);
|
||||
String8 name = coff_name_from_section_header(string_table, header);
|
||||
|
||||
DW_SectionKind s = dw_section_kind_from_string(name);
|
||||
B32 is_dwo = 0;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#ifndef DWARF_COFF_H
|
||||
#define DWARF_COFF_H
|
||||
|
||||
internal DW_Input dw_input_from_coff_section_table(Arena *arena, String8 raw_image, U64 string_table_off, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal DW_Input dw_input_from_coff_section_table(Arena *arena, String8 raw_image, String8 string_table, U64 section_count, COFF_SectionHeader *section_table);
|
||||
|
||||
#endif // DWARF_COFF_H
|
||||
|
||||
|
||||
+188
-175
@@ -315,106 +315,50 @@ lnk_sect_defn_list_concat_in_place_arr(LNK_SectDefnList *list, LNK_SectDefnList
|
||||
internal
|
||||
THREAD_POOL_TASK_FUNC(lnk_obj_initer)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
LNK_ObjIniter *task = raw_task;
|
||||
LNK_InputObj *input = task->inputs[task_id];
|
||||
U64 obj_idx = task->obj_id_base + task_id;
|
||||
LNK_ObjNode *obj_node = task->obj_node_arr + task_id;
|
||||
LNK_Obj *obj = &obj_node->data;
|
||||
LNK_ObjIniter *task = raw_task;
|
||||
LNK_InputObj *input = task->inputs[task_id];
|
||||
LNK_Obj *obj = &task->obj_node_arr[task_id].data;
|
||||
U64 obj_idx = task->obj_id_base + task_id;
|
||||
|
||||
String8 cached_path = push_str8_copy(arena, input->path);
|
||||
String8 cached_lib_path = push_str8_copy(arena, input->lib_path);
|
||||
|
||||
// parse coff obj
|
||||
//
|
||||
// parse obj header
|
||||
//
|
||||
COFF_FileHeaderInfo coff_info = coff_file_header_info_from_data(input->data);
|
||||
Rng1U64 coff_file_header_range = rng_1u64(0, coff_info.header_size);
|
||||
Rng1U64 coff_sect_arr_range = rng_1u64(coff_info.section_array_off, coff_info.section_array_off + coff_info.section_count_no_null * sizeof(COFF_SectionHeader));
|
||||
Rng1U64 coff_symbols_range = rng_1u64(coff_info.symbol_off, coff_info.symbol_off + coff_info.symbol_count * coff_info.symbol_size);
|
||||
String8 raw_coff_sect_arr = str8_substr(input->data, coff_sect_arr_range);
|
||||
String8 raw_coff_symbols = str8_substr(input->data, coff_symbols_range);
|
||||
String8 raw_coff_section_table = str8_substr(input->data, coff_info.section_table_range);
|
||||
String8 raw_coff_symbol_table = str8_substr(input->data, coff_info.symbol_table_range);
|
||||
String8 raw_coff_string_table = str8_substr(input->data, coff_info.string_table_range);
|
||||
|
||||
if (raw_coff_sect_arr.size != dim_1u64(coff_sect_arr_range)) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, cached_path, cached_lib_path, "corrupted file, unable to read section header table");
|
||||
//
|
||||
// error check: section table / symbol table / string table
|
||||
//
|
||||
if (raw_coff_section_table.size != dim_1u64(coff_info.section_table_range)) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "corrupted file, unable to read section header table");
|
||||
}
|
||||
if (raw_coff_symbols.size != dim_1u64(coff_symbols_range)) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, cached_path, cached_lib_path, "corrupted file, unable to read symbol table");
|
||||
if (raw_coff_symbol_table.size != dim_1u64(coff_info.symbol_table_range)) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "corrupted file, unable to read symbol table");
|
||||
}
|
||||
if (raw_coff_string_table.size != dim_1u64(coff_info.string_table_range)) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "corrupted file, unable to read string table");
|
||||
}
|
||||
|
||||
COFF_SectionHeader *coff_sect_arr = (COFF_SectionHeader *)raw_coff_sect_arr.str;
|
||||
void *coff_symbols = raw_coff_symbols.str;
|
||||
U64 chunk_count = coff_info.section_count_no_null + /* :common_block */ 1;
|
||||
String8 *sect_name_arr = push_array_no_zero(arena, String8, chunk_count);
|
||||
String8 *sect_sort_arr = push_array_no_zero(arena, String8, chunk_count);
|
||||
LNK_Chunk *chunk_arr = push_array(arena, LNK_Chunk, chunk_count);
|
||||
LNK_ChunkPtr *chunk_ptr_arr = push_array_no_zero(arena, LNK_ChunkPtr, chunk_count);
|
||||
|
||||
// :function_pad_min
|
||||
U64 function_pad_min;
|
||||
if (task->function_pad_min) {
|
||||
function_pad_min = *task->function_pad_min;
|
||||
} else {
|
||||
function_pad_min = lnk_get_default_function_pad_min(coff_info.machine);
|
||||
for (U64 chunk_idx = 0; chunk_idx < chunk_count; chunk_idx += 1) {
|
||||
chunk_ptr_arr[chunk_idx] = &chunk_arr[chunk_idx];
|
||||
}
|
||||
|
||||
U64 chunk_count = 1; // :common_block
|
||||
chunk_count += coff_info.section_count_no_null;
|
||||
//
|
||||
// setup :common_block
|
||||
//
|
||||
|
||||
String8 *sect_name_arr = push_array_no_zero(arena, String8, chunk_count);
|
||||
String8 *sect_sort_arr = push_array_no_zero(arena, String8, chunk_count);
|
||||
LNK_Chunk *chunk_arr = push_array(arena, LNK_Chunk, chunk_count);
|
||||
|
||||
// :common_block
|
||||
U64 common_block_idx = chunk_count - 1;
|
||||
sect_name_arr[common_block_idx] = str8_lit(".bss");
|
||||
sect_sort_arr[common_block_idx] = str8_lit("~");
|
||||
|
||||
for (U64 sect_idx = 0; sect_idx < coff_info.section_count_no_null; sect_idx += 1) {
|
||||
COFF_SectionHeader *coff_sect = &coff_sect_arr[sect_idx];
|
||||
|
||||
// read name
|
||||
String8 sect_name = coff_name_from_section_header(input->data, coff_sect, coff_info.string_table_off);
|
||||
|
||||
// parse section name
|
||||
coff_parse_section_name(sect_name, §_name_arr[sect_idx], §_sort_arr[sect_idx]);
|
||||
|
||||
String8 data;
|
||||
if (coff_sect->flags & COFF_SectionFlag_CntUninitializedData) {
|
||||
data = str8(0, coff_sect->fsize);
|
||||
} else {
|
||||
if (coff_sect->fsize > 0) {
|
||||
Rng1U64 range = rng_1u64(coff_sect->foff, coff_sect->foff + coff_sect->fsize);
|
||||
data = str8_substr(input->data, range);
|
||||
|
||||
if (contains_1u64(coff_file_header_range, coff_sect->foff) ||
|
||||
(coff_sect->fsize > 0 && contains_1u64(coff_file_header_range, coff_sect->foff + coff_sect->fsize-1))) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, cached_path, cached_lib_path, "header (%S No. %#llx) defines out of bounds section data (file offsets point into file header)", sect_name, sect_idx+1);
|
||||
}
|
||||
if (contains_1u64(coff_sect_arr_range, coff_sect->foff) ||
|
||||
(coff_sect->fsize > 0 && contains_1u64(coff_sect_arr_range, coff_sect->foff + coff_sect->fsize-1))) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, cached_path, cached_lib_path, "header (%S No. %#llx) defines out of bounds section data (file offsets point into section header table)", sect_name, sect_idx+1);
|
||||
}
|
||||
if (contains_1u64(coff_symbols_range, coff_sect->foff) ||
|
||||
(coff_sect->fsize > 0 && contains_1u64(coff_symbols_range, coff_sect->foff + coff_sect->fsize-1))) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, cached_path, cached_lib_path, "header (%S No. %#llx) defines out of bounds section data (file offsets point into symbol table)", sect_name, sect_idx+1);
|
||||
}
|
||||
if (dim_1u64(range) != coff_sect->fsize) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, cached_path, cached_lib_path, "header (%S No. %#llx) defines out of bounds section data", sect_name, sect_idx+1);
|
||||
}
|
||||
} else {
|
||||
data = str8_zero();
|
||||
}
|
||||
}
|
||||
|
||||
LNK_Chunk *chunk = &chunk_arr[sect_idx];
|
||||
chunk->align = coff_align_size_from_section_flags(coff_sect->flags);
|
||||
chunk->is_discarded = !!(coff_sect->flags & COFF_SectionFlag_LnkRemove);
|
||||
chunk->sort_chunk = 1;
|
||||
chunk->type = LNK_Chunk_Leaf;
|
||||
chunk->sort_idx = sect_sort_arr[sect_idx];
|
||||
chunk->input_idx = LNK_MakeChunkInputIdx(obj_idx, sect_idx);
|
||||
chunk->flags = coff_sect->flags;
|
||||
chunk->u.leaf = data;
|
||||
chunk->obj = obj;
|
||||
lnk_chunk_set_debugf(arena, chunk, "obj_idx %llx isect %llx", obj_idx, sect_idx);
|
||||
}
|
||||
|
||||
// :common_block
|
||||
LNK_Chunk *master_common_block = &chunk_arr[common_block_idx];
|
||||
master_common_block->ref = lnk_chunk_ref(0,0); // :chunk_ref_assign
|
||||
master_common_block->align = 1;
|
||||
@@ -427,23 +371,119 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer)
|
||||
master_common_block->associate = 0;
|
||||
master_common_block->u.list = push_array(arena, LNK_ChunkList, 1);
|
||||
master_common_block->obj = obj;
|
||||
lnk_chunk_set_debugf(arena, master_common_block, "master common block");
|
||||
lnk_chunk_set_debugf(arena, master_common_block, "obj[%llx] master common block", obj_idx);
|
||||
|
||||
LNK_ChunkPtr *chunk_ptr_arr = push_array_no_zero(arena, LNK_ChunkPtr, chunk_count);
|
||||
for (U64 i = 0; i < chunk_count; ++i) {
|
||||
chunk_ptr_arr[i] = &chunk_arr[i];
|
||||
//
|
||||
// parse section table
|
||||
//
|
||||
COFF_SectionHeader *coff_section_table = (COFF_SectionHeader *)raw_coff_section_table.str;
|
||||
for (U64 sect_idx = 0; sect_idx < coff_info.section_count_no_null; sect_idx += 1) {
|
||||
COFF_SectionHeader *coff_sect_header = &coff_section_table[sect_idx];
|
||||
|
||||
// read name
|
||||
String8 sect_name = coff_name_from_section_header(raw_coff_string_table, coff_sect_header);
|
||||
|
||||
// parse name
|
||||
coff_parse_section_name(sect_name, §_name_arr[sect_idx], §_sort_arr[sect_idx]);
|
||||
|
||||
// find contents
|
||||
String8 sect_data;
|
||||
if (coff_sect_header->flags & COFF_SectionFlag_CntUninitializedData) {
|
||||
sect_data = str8(0, coff_sect_header->fsize);
|
||||
} else {
|
||||
if (coff_sect_header->fsize > 0) {
|
||||
Rng1U64 sect_range = rng_1u64(coff_sect_header->foff, coff_sect_header->foff + coff_sect_header->fsize);
|
||||
sect_data = str8_substr(input->data, sect_range);
|
||||
|
||||
if (contains_1u64(coff_info.header_range, coff_sect_header->foff) ||
|
||||
(coff_sect_header->fsize > 0 && contains_1u64(coff_info.header_range, sect_range.max-1))) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "header (%S No. %#llx) defines out of bounds section data (file offsets point into file header)", sect_name, sect_idx+1);
|
||||
}
|
||||
if (contains_1u64(coff_info.section_table_range, coff_sect_header->foff) ||
|
||||
(coff_sect_header->fsize > 0 && contains_1u64(coff_info.section_table_range, sect_range.max-1))) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "header (%S No. %#llx) defines out of bounds section data (file offsets point into section header table)", sect_name, sect_idx+1);
|
||||
}
|
||||
if (contains_1u64(coff_info.symbol_table_range, coff_sect_header->foff) ||
|
||||
(coff_sect_header->fsize > 0 && contains_1u64(coff_info.symbol_table_range, sect_range.max-1))) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "header (%S No. %#llx) defines out of bounds section data (file offsets point into symbol table)", sect_name, sect_idx+1);
|
||||
}
|
||||
if (dim_1u64(sect_range) != coff_sect_header->fsize) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, input->path, input->lib_path, "header (%S No. %#llx) defines out of bounds section data", sect_name, sect_idx+1);
|
||||
}
|
||||
} else {
|
||||
sect_data = str8_zero();
|
||||
}
|
||||
}
|
||||
|
||||
// fill out chunk
|
||||
LNK_Chunk *chunk = &chunk_arr[sect_idx];
|
||||
chunk->align = coff_align_size_from_section_flags(coff_sect_header->flags);
|
||||
chunk->is_discarded = !!(coff_sect_header->flags & COFF_SectionFlag_LnkRemove);
|
||||
chunk->sort_chunk = 1;
|
||||
chunk->type = LNK_Chunk_Leaf;
|
||||
chunk->sort_idx = sect_sort_arr[sect_idx];
|
||||
chunk->input_idx = LNK_MakeChunkInputIdx(obj_idx, sect_idx);
|
||||
chunk->flags = coff_sect_header->flags;
|
||||
chunk->u.leaf = sect_data;
|
||||
chunk->obj = obj;
|
||||
lnk_chunk_set_debugf(arena, chunk, "obj[%llx] sect[%llx]", obj_idx, sect_idx);
|
||||
}
|
||||
|
||||
//
|
||||
// :function_pad_min
|
||||
//
|
||||
U64 function_pad_min;
|
||||
if (task->function_pad_min) {
|
||||
function_pad_min = *task->function_pad_min;
|
||||
} else {
|
||||
function_pad_min = lnk_get_default_function_pad_min(coff_info.machine);
|
||||
}
|
||||
|
||||
//
|
||||
// convert from COFF
|
||||
//
|
||||
void *coff_symbol_table = raw_coff_symbol_table.str;
|
||||
LNK_SymbolArray symbol_arr = lnk_symbol_array_from_coff(arena, obj, input->path, input->lib_path, coff_info.is_big_obj, function_pad_min, coff_info.section_count_no_null, coff_section_table, coff_info.symbol_count, coff_symbol_table, raw_coff_string_table, chunk_ptr_arr, master_common_block);
|
||||
LNK_SymbolList symbol_list = lnk_symbol_list_from_array(arena, symbol_arr);
|
||||
LNK_RelocList *reloc_list_arr = lnk_reloc_list_array_from_coff(arena, coff_info.machine, input->data, coff_info.section_count_no_null, coff_section_table, chunk_ptr_arr, symbol_arr);
|
||||
|
||||
//
|
||||
// parse directives
|
||||
//
|
||||
LNK_DirectiveInfo directive_info = lnk_directive_info_from_sections(arena, input->path, input->lib_path, coff_info.section_count_no_null, reloc_list_arr, sect_name_arr, chunk_arr);
|
||||
|
||||
// parse exports
|
||||
LNK_ExportParseList export_parse = {0};
|
||||
for (LNK_Directive *dir = directive_info.v[LNK_CmdSwitch_Export].first; dir != 0; dir = dir->next) {
|
||||
lnk_parse_export_directive(arena, &export_parse, dir->value_list, input->path, input->lib_path);
|
||||
}
|
||||
|
||||
// push /export symbols
|
||||
for (LNK_ExportParse *exp = export_parse.first; exp != 0; exp = exp->next) {
|
||||
LNK_Symbol *symbol = lnk_make_undefined_symbol(arena, exp->name, LNK_SymbolScopeFlag_Main);
|
||||
lnk_symbol_list_push(arena, &symbol_list, symbol);
|
||||
}
|
||||
|
||||
// push /include symbols
|
||||
String8List include_symbol_list = {0};
|
||||
for (LNK_Directive *dir = directive_info.v[LNK_CmdSwitch_Include].first; dir != 0; dir = dir->next) {
|
||||
str8_list_concat_in_place(&include_symbol_list, &dir->value_list);
|
||||
}
|
||||
|
||||
// parse /alternatename
|
||||
LNK_AltNameList alt_name_list = {0};
|
||||
for (LNK_Directive *dir = directive_info.v[LNK_CmdSwitch_AlternateName].first; dir != 0; dir = dir->next) {
|
||||
String8 *invalid_string = lnk_parse_alt_name_directive_list(arena, dir->value_list, &alt_name_list);
|
||||
if (invalid_string != 0) {
|
||||
lnk_error_with_loc(LNK_Error_Cmdl, input->path, input->lib_path, "invalid syntax \"%S\", expected format \"FROM=TO\"", *invalid_string);
|
||||
}
|
||||
}
|
||||
|
||||
// convert from coff
|
||||
LNK_SymbolArray symbol_arr = lnk_symbol_array_from_coff(arena, input->data, obj, cached_path, cached_lib_path, coff_info.is_big_obj, function_pad_min, coff_info.string_table_off, coff_info.section_count_no_null, coff_sect_arr, coff_info.symbol_count, coff_symbols, chunk_ptr_arr, master_common_block);
|
||||
LNK_SymbolList symbol_list = lnk_symbol_list_from_array(arena, symbol_arr);
|
||||
LNK_RelocList *reloc_list_arr = lnk_reloc_list_array_from_coff(arena, coff_info.machine, input->data, coff_info.section_count_no_null, coff_sect_arr, chunk_ptr_arr, symbol_arr);
|
||||
LNK_DirectiveInfo directive_info = lnk_directive_info_from_sections(arena, cached_path, cached_lib_path, coff_info.section_count_no_null, reloc_list_arr, sect_name_arr, chunk_arr);
|
||||
|
||||
// fill out obj
|
||||
obj->data = input->data;
|
||||
obj->path = cached_path;
|
||||
obj->lib_path = cached_lib_path;
|
||||
obj->path = push_str8_copy(arena, input->path);
|
||||
obj->lib_path = push_str8_copy(arena, input->lib_path);
|
||||
obj->input_idx = obj_idx;
|
||||
obj->machine = coff_info.machine;
|
||||
obj->chunk_count = chunk_count;
|
||||
@@ -454,33 +494,9 @@ THREAD_POOL_TASK_FUNC(lnk_obj_initer)
|
||||
obj->symbol_list = symbol_list;
|
||||
obj->sect_reloc_list_arr = reloc_list_arr;
|
||||
obj->directive_info = directive_info;
|
||||
|
||||
// parse exports
|
||||
LNK_ExportParseList export_parse = {0};
|
||||
for (LNK_Directive *dir = obj->directive_info.v[LNK_CmdSwitch_Export].first; dir != 0; dir = dir->next) {
|
||||
lnk_parse_export_directive(arena, &obj->export_parse, dir->value_list, obj->path, obj->lib_path);
|
||||
}
|
||||
|
||||
// push /export symbols
|
||||
for (LNK_ExportParse *exp = export_parse.first; exp != 0; exp = exp->next) {
|
||||
LNK_Symbol *symbol = lnk_make_undefined_symbol(arena, exp->name, LNK_SymbolScopeFlag_Main);
|
||||
lnk_symbol_list_push(arena, &obj->symbol_list, symbol);
|
||||
}
|
||||
|
||||
// push /include symbols
|
||||
for (LNK_Directive *dir = obj->directive_info.v[LNK_CmdSwitch_Include].first; dir != 0; dir = dir->next) {
|
||||
str8_list_concat_in_place(&obj->include_symbol_list, &dir->value_list);
|
||||
}
|
||||
|
||||
// parse /alternatename
|
||||
for (LNK_Directive *dir = obj->directive_info.v[LNK_CmdSwitch_AlternateName].first; dir != 0; dir = dir->next) {
|
||||
String8 *invalid_string = lnk_parse_alt_name_directive_list(arena, dir->value_list, &obj->alt_name_list);
|
||||
if (invalid_string != 0) {
|
||||
lnk_error_obj(LNK_Error_Cmdl, obj, "invalid syntax \"%S\", expected format \"FROM=TO\"", *invalid_string);
|
||||
}
|
||||
}
|
||||
|
||||
scratch_end(scratch);
|
||||
obj->export_parse = export_parse;
|
||||
obj->include_symbol_list = include_symbol_list;
|
||||
obj->alt_name_list = alt_name_list;
|
||||
}
|
||||
|
||||
internal
|
||||
@@ -528,14 +544,14 @@ THREAD_POOL_TASK_FUNC(lnk_chunk_counter)
|
||||
LNK_ChunkCounter *task = raw_task;
|
||||
LNK_Obj *obj = &task->obj_arr[obj_idx].data;
|
||||
for (U64 chunk_idx = 0; chunk_idx < obj->chunk_count; chunk_idx += 1) {
|
||||
String8 name = obj->sect_name_arr[chunk_idx];
|
||||
String8 name = obj->sect_name_arr[chunk_idx];
|
||||
LNK_Chunk *chunk = obj->chunk_arr[chunk_idx];
|
||||
LNK_Section *sect = lnk_section_table_search(task->st, name);
|
||||
|
||||
U64 count = 0;
|
||||
lnk_visit_chunks(0, chunk, lnk_chunk_get_count_cb, &count);
|
||||
|
||||
task->chunk_count_arr_arr[sect->id][obj_idx] += count;
|
||||
task->chunk_counts[sect->id][obj_idx] += count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,8 +561,8 @@ LNK_CHUNK_VISITOR_SIG(lnk_chunk_ref_assign)
|
||||
LNK_ChunkRefAssign *ctx = ud;
|
||||
|
||||
// alloc chunk id
|
||||
U64 chunk_id = ctx->chunk_id_arr_arr[sect_id][ctx->obj_idx];
|
||||
ctx->chunk_id_arr_arr[sect_id][ctx->obj_idx] += 1;
|
||||
U64 chunk_id = *ctx->chunk_id;
|
||||
*ctx->chunk_id += 1;
|
||||
|
||||
// set chunk ref
|
||||
chunk->ref = lnk_chunk_ref(sect_id, chunk_id);
|
||||
@@ -571,13 +587,11 @@ THREAD_POOL_TASK_FUNC(lnk_chunk_ref_assigner)
|
||||
|
||||
// :find_chunk_section
|
||||
LNK_Section *sect = lnk_section_table_search(task->st, name);
|
||||
Assert(sect);
|
||||
|
||||
// :chunk_ref_assign
|
||||
LNK_ChunkRefAssign ctx;
|
||||
ctx.cman = sect->cman;
|
||||
ctx.chunk_id_arr_arr = task->chunk_id_arr_arr;
|
||||
ctx.obj_idx = obj_idx;
|
||||
LNK_ChunkRefAssign ctx = {0};
|
||||
ctx.cman = sect->cman;
|
||||
ctx.chunk_id = &task->chunk_ids[sect->id][obj_idx];
|
||||
lnk_visit_chunks(sect->id, chunk, lnk_chunk_ref_assign, &ctx);
|
||||
|
||||
// push to section chunk list
|
||||
@@ -684,27 +698,27 @@ lnk_obj_list_push_parallel(TP_Context *tp,
|
||||
ProfEnd();
|
||||
|
||||
ProfBegin("Count Chunks Per Section");
|
||||
U64 **chunk_id_arr_arr;
|
||||
U64 **chunk_ids;
|
||||
{
|
||||
U64 **chunk_count_arr_arr = push_array_no_zero(scratch.arena, U64 *, st->id_max);
|
||||
U64 **chunk_counts = push_array_no_zero(scratch.arena, U64 *, st->id_max);
|
||||
for (U64 sect_idx = 0; sect_idx < st->id_max; sect_idx += 1) {
|
||||
chunk_count_arr_arr[sect_idx] = push_array(scratch.arena, U64, obj_arr.count);
|
||||
chunk_counts[sect_idx] = push_array(scratch.arena, U64, obj_arr.count);
|
||||
}
|
||||
|
||||
LNK_ChunkCounter task;
|
||||
task.st = st;
|
||||
task.obj_arr = obj_arr.v;
|
||||
task.chunk_count_arr_arr = chunk_count_arr_arr;
|
||||
LNK_ChunkCounter task = {0};
|
||||
task.st = st;
|
||||
task.obj_arr = obj_arr.v;
|
||||
task.chunk_counts = chunk_counts;
|
||||
tp_for_parallel(tp, 0, obj_arr.count, lnk_chunk_counter, &task);
|
||||
|
||||
chunk_id_arr_arr = chunk_count_arr_arr;
|
||||
chunk_ids = chunk_counts;
|
||||
for (U64 sect_idx = 1; sect_idx < st->id_max; sect_idx += 1) {
|
||||
LNK_Section *sect = lnk_section_table_search_id(st, sect_idx);
|
||||
if (!sect) continue;
|
||||
for (U64 obj_idx = 0; obj_idx < obj_arr.count; obj_idx += 1) {
|
||||
U64 chunk_id_base = sect->cman->total_chunk_count;
|
||||
sect->cman->total_chunk_count += chunk_count_arr_arr[sect_idx][obj_idx];
|
||||
chunk_id_arr_arr[sect_idx][obj_idx] = chunk_id_base;
|
||||
sect->cman->total_chunk_count += chunk_counts[sect_idx][obj_idx];
|
||||
chunk_ids[sect_idx][obj_idx] = chunk_id_base;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -715,7 +729,7 @@ lnk_obj_list_push_parallel(TP_Context *tp,
|
||||
LNK_ChunkRefAssigner task;
|
||||
task.st = st;
|
||||
task.range_arr = tp_divide_work(scratch.arena, obj_arr.count, tp->worker_count);
|
||||
task.chunk_id_arr_arr = chunk_id_arr_arr;
|
||||
task.chunk_ids = chunk_ids;
|
||||
task.obj_arr = obj_arr.v;
|
||||
task.nosort_chunk_list_arr_arr = lnk_make_chunk_list_arr_arr(scratch.arena, st->id_max, tp->worker_count);
|
||||
task.chunk_list_arr_arr = lnk_make_chunk_list_arr_arr(scratch.arena, st->id_max, tp->worker_count);
|
||||
@@ -738,28 +752,27 @@ lnk_obj_list_push_parallel(TP_Context *tp,
|
||||
|
||||
internal LNK_SymbolArray
|
||||
lnk_symbol_array_from_coff(Arena *arena,
|
||||
String8 raw_coff,
|
||||
LNK_Obj *obj,
|
||||
String8 obj_path,
|
||||
String8 lib_path,
|
||||
B32 is_big_obj,
|
||||
U64 function_pad_min,
|
||||
U64 string_table_off,
|
||||
U64 sect_count,
|
||||
COFF_SectionHeader *coff_sect_arr,
|
||||
U64 coff_symbol_count,
|
||||
void *coff_symbols,
|
||||
LNK_ChunkPtr *chunk_ptr_arr,
|
||||
COFF_SectionHeader *section_table,
|
||||
U64 symbol_count,
|
||||
void *symbol_table,
|
||||
String8 string_table,
|
||||
LNK_ChunkPtr *chunk_table,
|
||||
LNK_Chunk *master_common_block)
|
||||
{
|
||||
if (function_pad_min) {
|
||||
COFF_ParsedSymbol symbol;
|
||||
for (U64 symbol_idx = 0; symbol_idx < coff_symbol_count; symbol_idx += (1 + symbol.aux_symbol_count)) {
|
||||
for (U64 symbol_idx = 0; symbol_idx < symbol_count; symbol_idx += (1 + symbol.aux_symbol_count)) {
|
||||
// read symbol
|
||||
if (is_big_obj) {
|
||||
symbol = coff_parse_symbol32(raw_coff, string_table_off, &((COFF_Symbol32 *)coff_symbols)[symbol_idx]);
|
||||
symbol = coff_parse_symbol32(string_table, &((COFF_Symbol32 *)symbol_table)[symbol_idx]);
|
||||
} else {
|
||||
symbol = coff_parse_symbol16(raw_coff, string_table_off, &((COFF_Symbol16 *)coff_symbols)[symbol_idx]);
|
||||
symbol = coff_parse_symbol16(string_table, &((COFF_Symbol16 *)symbol_table)[symbol_idx]);
|
||||
}
|
||||
|
||||
// is this a function symbol?
|
||||
@@ -768,11 +781,11 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
if (symbol.section_number == 0 || symbol.section_number > sect_count) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "out ouf bounds section index in symbol \"%S (%u)\"", symbol.name, symbol.section_number);
|
||||
}
|
||||
if (symbol.value > coff_sect_arr[symbol.section_number-1].fsize) {
|
||||
if (symbol.value > section_table[symbol.section_number-1].fsize) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "out of bounds section offset in symbol \"%S (%u)\"", symbol.name, symbol.value);
|
||||
}
|
||||
|
||||
LNK_Chunk *chunk = chunk_ptr_arr[symbol.section_number-1];
|
||||
LNK_Chunk *chunk = chunk_table[symbol.section_number-1];
|
||||
if (symbol.value > 0) {
|
||||
// convert leaf to list
|
||||
//
|
||||
@@ -805,7 +818,7 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
chunk = chunk_list;
|
||||
|
||||
// set list chunk to be head of this section
|
||||
chunk_ptr_arr[symbol.section_number-1] = chunk_list;
|
||||
chunk_table[symbol.section_number-1] = chunk_list;
|
||||
}
|
||||
|
||||
// find chunk that is near symbol
|
||||
@@ -860,23 +873,23 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
}
|
||||
|
||||
LNK_SymbolArray symbol_array = {0};
|
||||
symbol_array.count = coff_symbol_count;
|
||||
symbol_array.count = symbol_count;
|
||||
symbol_array.v = push_array(arena, LNK_Symbol, symbol_array.count);
|
||||
|
||||
COFF_ParsedSymbol parsed_symbol;
|
||||
for (U64 symbol_idx = 0; symbol_idx < coff_symbol_count; symbol_idx += (1 + parsed_symbol.aux_symbol_count)) {
|
||||
for (U64 symbol_idx = 0; symbol_idx < symbol_count; symbol_idx += (1 + parsed_symbol.aux_symbol_count)) {
|
||||
void *aux_symbols;
|
||||
if (is_big_obj) {
|
||||
COFF_Symbol32 *ptr = &((COFF_Symbol32 *)coff_symbols)[symbol_idx];
|
||||
parsed_symbol = coff_parse_symbol32(raw_coff, string_table_off, ptr);
|
||||
aux_symbols = parsed_symbol.aux_symbol_count ? ptr+1 : 0;
|
||||
COFF_Symbol32 *ptr = &((COFF_Symbol32 *)symbol_table)[symbol_idx];
|
||||
parsed_symbol = coff_parse_symbol32(string_table, ptr);
|
||||
aux_symbols = parsed_symbol.aux_symbol_count ? ptr+1 : 0;
|
||||
} else {
|
||||
COFF_Symbol16 *ptr = (COFF_Symbol16 *)coff_symbols + symbol_idx;
|
||||
parsed_symbol = coff_parse_symbol16(raw_coff, string_table_off, ptr);
|
||||
aux_symbols = parsed_symbol.aux_symbol_count ? ptr+1 : 0;
|
||||
COFF_Symbol16 *ptr = (COFF_Symbol16 *)symbol_table + symbol_idx;
|
||||
parsed_symbol = coff_parse_symbol16(string_table, ptr);
|
||||
aux_symbols = parsed_symbol.aux_symbol_count ? ptr+1 : 0;
|
||||
}
|
||||
|
||||
if (symbol_idx + parsed_symbol.aux_symbol_count + 1 > coff_symbol_count) {
|
||||
if (symbol_idx + parsed_symbol.aux_symbol_count + 1 > symbol_count) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "symbol %S (No. %llx) has out of bounds aux symbol count %llu", parsed_symbol.name, symbol_idx, parsed_symbol.aux_symbol_count);
|
||||
}
|
||||
|
||||
@@ -886,7 +899,7 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
if (parsed_symbol.section_number == 0 || parsed_symbol.section_number > sect_count) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "symbol %S (No. %llx) has out ouf bounds section index %x", parsed_symbol.name, symbol_idx, parsed_symbol.section_number);
|
||||
}
|
||||
if (parsed_symbol.value > coff_sect_arr[parsed_symbol.section_number-1].fsize) {
|
||||
if (parsed_symbol.value > section_table[parsed_symbol.section_number-1].fsize) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "symbol %S (No. %llx) has out of bounds section offset %x into section %x", parsed_symbol.name, symbol_idx, parsed_symbol.value, parsed_symbol.section_number);
|
||||
}
|
||||
|
||||
@@ -901,13 +914,13 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
}
|
||||
|
||||
|
||||
LNK_Chunk *chunk = chunk_ptr_arr[parsed_symbol.section_number-1];
|
||||
LNK_Chunk *chunk = chunk_table[parsed_symbol.section_number-1];
|
||||
U64 offset = parsed_symbol.value;
|
||||
COFF_ComdatSelectType selection = COFF_ComdatSelect_Any;
|
||||
U64 check_sum = 0;
|
||||
|
||||
|
||||
B32 is_comdat = (coff_sect_arr[parsed_symbol.section_number-1].flags & COFF_SectionFlag_LnkCOMDAT) &&
|
||||
B32 is_comdat = (section_table[parsed_symbol.section_number-1].flags & COFF_SectionFlag_LnkCOMDAT) &&
|
||||
parsed_symbol.value == 0 &&
|
||||
parsed_symbol.aux_symbol_count > 0 &&
|
||||
parsed_symbol.type.u.lsb == COFF_SymType_Null &&
|
||||
@@ -929,8 +942,8 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
|
||||
// associate chunks
|
||||
if (secdef_number > 0 && secdef_number <= sect_count) {
|
||||
LNK_Chunk *head_chunk = chunk_ptr_arr[secdef_number-1];
|
||||
LNK_Chunk *associate_chunk = chunk_ptr_arr[parsed_symbol.section_number-1];
|
||||
LNK_Chunk *head_chunk = chunk_table[secdef_number-1];
|
||||
LNK_Chunk *associate_chunk = chunk_table[parsed_symbol.section_number-1];
|
||||
lnk_chunk_associate(head_chunk, associate_chunk);
|
||||
} else {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "symbol %S (No. %llx) has out of bounds section definition number %u", parsed_symbol.name, symbol_idx, secdef_number);
|
||||
@@ -964,7 +977,7 @@ lnk_symbol_array_from_coff(Arena *arena,
|
||||
}
|
||||
|
||||
COFF_SymbolWeakExt *weak_ext = aux_symbols;
|
||||
if (weak_ext->tag_index >= coff_symbol_count) {
|
||||
if (weak_ext->tag_index >= symbol_count) {
|
||||
lnk_error_with_loc(LNK_Error_IllData, obj_path, lib_path, "weak symbol \"%S (%u)\" points to out of bounds symbol", parsed_symbol.name, symbol_idx);
|
||||
}
|
||||
|
||||
@@ -1029,10 +1042,10 @@ lnk_reloc_list_array_from_coff(Arena *arena, COFF_MachineType machine, String8 c
|
||||
{
|
||||
LNK_RelocList *reloc_list_arr = push_array_no_zero(arena, LNK_RelocList, sect_count);
|
||||
for (U64 sect_idx = 0; sect_idx < sect_count; ++sect_idx) {
|
||||
COFF_SectionHeader *COFF_FileHeader = &coff_sect_arr[sect_idx];
|
||||
COFF_RelocInfo coff_reloc_info = coff_reloc_info_from_section_header(coff_data, COFF_FileHeader);
|
||||
COFF_Reloc *coff_reloc_v = (COFF_Reloc *)(coff_data.str + coff_reloc_info.array_off);
|
||||
LNK_Chunk *sect_chunk = chunk_ptr_arr[sect_idx];
|
||||
COFF_SectionHeader *coff_sect_header = &coff_sect_arr[sect_idx];
|
||||
COFF_RelocInfo coff_reloc_info = coff_reloc_info_from_section_header(coff_data, coff_sect_header);
|
||||
COFF_Reloc *coff_reloc_v = (COFF_Reloc *)(coff_data.str + coff_reloc_info.array_off);
|
||||
LNK_Chunk *sect_chunk = chunk_ptr_arr[sect_idx];
|
||||
reloc_list_arr[sect_idx] = lnk_reloc_list_from_coff_reloc_array(arena, machine, sect_chunk, symbol_array, coff_reloc_v, coff_reloc_info.count);
|
||||
}
|
||||
return reloc_list_arr;
|
||||
|
||||
@@ -128,21 +128,20 @@ typedef struct
|
||||
{
|
||||
LNK_SectionTable *st;
|
||||
LNK_ObjNode *obj_arr;
|
||||
U64 **chunk_count_arr_arr;
|
||||
U64 **chunk_counts;
|
||||
} LNK_ChunkCounter;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LNK_ChunkManager *cman;
|
||||
U64 **chunk_id_arr_arr;
|
||||
U64 obj_idx;
|
||||
U64 *chunk_id;
|
||||
} LNK_ChunkRefAssign;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LNK_SectionTable *st;
|
||||
Rng1U64 *range_arr;
|
||||
U64 **chunk_id_arr_arr;
|
||||
U64 **chunk_ids;
|
||||
LNK_ObjNode *obj_arr;
|
||||
LNK_ChunkList **nosort_chunk_list_arr_arr;
|
||||
LNK_ChunkList **chunk_list_arr_arr;
|
||||
@@ -202,7 +201,7 @@ internal LNK_ChunkList * lnk_collect_obj_chunks(TP_Context *tp, TP_Arena *arena
|
||||
internal LNK_ObjNodeArray lnk_obj_list_push_parallel(TP_Context *tp, TP_Arena *tp_arena, LNK_ObjList *obj_list, LNK_SectionTable *st, U64 *function_pad_min, U64 input_count, LNK_InputObj **inputs);
|
||||
|
||||
internal LNK_Chunk * lnk_sect_chunk_array_from_coff(Arena *arena, U64 obj_id, String8 obj_path, String8 coff_data, U64 sect_count, COFF_SectionHeader *coff_sect_arr, String8 *sect_name_arr, String8 *sect_postfix_arr);
|
||||
internal LNK_SymbolArray lnk_symbol_array_from_coff(Arena *arena, String8 coff_data, LNK_Obj *obj, String8 obj_path, String8 lib_path, B32 is_big_obj, U64 function_pad_min, U64 string_table_off, U64 sect_count, COFF_SectionHeader *coff_sect_arr, U64 coff_symbol_count, void *coff_symbols, LNK_ChunkPtr *chunk_ptr_arr, LNK_Chunk *master_common_block);
|
||||
internal LNK_SymbolArray lnk_symbol_array_from_coff(Arena *arena, LNK_Obj *obj, String8 obj_path, String8 lib_path, B32 is_big_obj, U64 function_pad_min, U64 sect_count, COFF_SectionHeader *section_table, U64 symbol_count, void *symbol_table, String8 string_table, LNK_ChunkPtr *chunk_table, LNK_Chunk *master_common_block);
|
||||
internal LNK_RelocList lnk_reloc_list_from_coff_reloc_array(Arena *arena, COFF_MachineType machine, LNK_Chunk *chunk, LNK_SymbolArray symbol_array, COFF_Reloc *reloc_v, U64 reloc_count);
|
||||
internal LNK_RelocList * lnk_reloc_list_array_from_coff(Arena *arena, COFF_MachineType machine, String8 coff_data, U64 sect_count, COFF_SectionHeader *coff_sect_arr, LNK_ChunkPtr *chunk_ptr_arr, LNK_SymbolArray symbol_array);
|
||||
internal LNK_DirectiveInfo lnk_directive_info_from_sections(Arena *arena, String8 obj_path, String8 lib_path, U64 chunk_count, LNK_RelocList *reloc_list_arr, String8 *sect_name_arr, LNK_Chunk *chunk_arr);
|
||||
|
||||
+19
-84
@@ -600,20 +600,20 @@ pe_bin_info_from_data(Arena *arena, String8 data)
|
||||
// rjf: fill info
|
||||
if(valid)
|
||||
{
|
||||
info.image_base = image_base;
|
||||
info.entry_point = entry_point;
|
||||
info.is_pe32 = (optional_magic == PE_PE32_MAGIC);
|
||||
info.virt_section_align = virt_section_align;
|
||||
info.file_section_align = file_section_align;
|
||||
info.section_array_off = sec_array_off;
|
||||
info.section_count = clamped_sec_count;
|
||||
info.symbol_array_off = symbol_array_off;
|
||||
info.symbol_count = symbol_count;
|
||||
info.string_table_off = string_table_off;
|
||||
info.data_dir_franges = data_dir_franges;
|
||||
info.data_dir_count = data_dir_count;
|
||||
info.arch = arch_from_coff_machine(file_header.machine);
|
||||
info.tls_header = tls_header;
|
||||
info.arch = arch_from_coff_machine(file_header.machine);
|
||||
info.image_base = image_base;
|
||||
info.entry_point = entry_point;
|
||||
info.is_pe32 = (optional_magic == PE_PE32_MAGIC);
|
||||
info.virt_section_align = virt_section_align;
|
||||
info.file_section_align = file_section_align;
|
||||
info.section_count = clamped_sec_count;
|
||||
info.symbol_count = symbol_count;
|
||||
info.section_table_range = rng_1u64(sec_array_off, sec_array_off + sizeof(COFF_SectionHeader) * clamped_sec_count);
|
||||
info.symbol_table_range = rng_1u64(symbol_array_off, symbol_array_off + sizeof(COFF_Symbol16) * symbol_count);
|
||||
info.string_table_range = rng_1u64(string_table_off, data.size);
|
||||
info.data_dir_franges = data_dir_franges;
|
||||
info.data_dir_count = data_dir_count;
|
||||
info.tls_header = tls_header;
|
||||
}
|
||||
|
||||
return info;
|
||||
@@ -762,80 +762,15 @@ pe_pdata_off_from_voff__binary_search_x8664(String8 raw_pdata, U64 voff)
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void *
|
||||
pe_ptr_from_voff(String8 data, PE_BinInfo *bin, U64 voff)
|
||||
{
|
||||
// rjf: get the section for this voff
|
||||
U64 sec_count = bin->section_count;
|
||||
COFF_SectionHeader *sec_array = (COFF_SectionHeader*)((U8*)data.str + bin->section_array_off);
|
||||
COFF_SectionHeader *sec_ptr = sec_array;
|
||||
COFF_SectionHeader *sec = 0;
|
||||
for(U64 i = 1; i <= sec_count; i += 1, sec_ptr += 1)
|
||||
{
|
||||
if(sec_ptr->voff <= voff && voff < sec_ptr->voff + sec_ptr->vsize)
|
||||
{
|
||||
sec = sec_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: adjust to file pointer
|
||||
void *result = 0;
|
||||
if(sec != 0 && sec_ptr->fsize > 0)
|
||||
{
|
||||
U64 off = voff - sec->voff + sec->foff;
|
||||
if(off < data.size)
|
||||
{
|
||||
result = data.str + off;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U64
|
||||
pe_section_num_from_voff(String8 data, PE_BinInfo *bin, U64 voff)
|
||||
{
|
||||
U64 sec_count = bin->section_count;
|
||||
COFF_SectionHeader *sec_array = (COFF_SectionHeader*)((U8*)data.str + bin->section_array_off);
|
||||
COFF_SectionHeader *sec_ptr = sec_array;
|
||||
U64 result = 0;
|
||||
for(U64 i = 1; i <= sec_count; i += 1, sec_ptr += 1)
|
||||
{
|
||||
if(sec_ptr->voff <= voff && voff < sec_ptr->voff + sec_ptr->vsize)
|
||||
{
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void *
|
||||
pe_ptr_from_section_num(String8 data, PE_BinInfo *bin, U64 n)
|
||||
{
|
||||
void *result = 0;
|
||||
U64 sec_count = bin->section_count;
|
||||
if(1 <= n && n <= sec_count)
|
||||
{
|
||||
COFF_SectionHeader *sec_array = (COFF_SectionHeader*)((U8*)data.str + bin->section_array_off);
|
||||
COFF_SectionHeader *sec = sec_array + n - 1;
|
||||
if(sec->fsize > 0)
|
||||
{
|
||||
result = data.str + sec->foff;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal U64
|
||||
pe_foff_from_voff(String8 data, PE_BinInfo *bin, U64 voff)
|
||||
{
|
||||
U64 foff = 0;
|
||||
COFF_SectionHeader *sections = (COFF_SectionHeader*)(data.str+bin->section_array_off);
|
||||
U64 section_count = bin->section_count;
|
||||
for(U64 sect_idx = 0; sect_idx < section_count; sect_idx += 1)
|
||||
U64 foff = 0;
|
||||
String8 raw_section_table = str8_substr(data, bin->section_table_range);
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_section_table.str;
|
||||
for(U64 sect_idx = 0; sect_idx < bin->section_count; sect_idx += 1)
|
||||
{
|
||||
COFF_SectionHeader *sect = §ions[sect_idx];
|
||||
COFF_SectionHeader *sect = §ion_table[sect_idx];
|
||||
if(sect->voff <= voff && voff < sect->voff + sect->vsize)
|
||||
{
|
||||
if(!(sect->flags & COFF_SectionFlag_CntUninitializedData))
|
||||
|
||||
+4
-7
@@ -993,17 +993,17 @@ struct PE_HandlerScope
|
||||
typedef struct PE_BinInfo PE_BinInfo;
|
||||
struct PE_BinInfo
|
||||
{
|
||||
Arch arch;
|
||||
U64 image_base;
|
||||
U64 entry_point;
|
||||
B32 is_pe32;
|
||||
U64 virt_section_align;
|
||||
U64 file_section_align;
|
||||
U64 section_array_off;
|
||||
U64 section_count;
|
||||
U64 symbol_array_off;
|
||||
U64 symbol_count;
|
||||
U64 string_table_off;
|
||||
Arch arch;
|
||||
Rng1U64 section_table_range;
|
||||
Rng1U64 symbol_table_range;
|
||||
Rng1U64 string_table_range;
|
||||
Rng1U64 *data_dir_franges;
|
||||
U32 data_dir_count;
|
||||
PE_TLSHeader64 tls_header;
|
||||
@@ -1085,9 +1085,6 @@ internal PE_ParsedTLS pe_tls_from_data(Arena *arena, COFF_MachineT
|
||||
//~ rjf: Helpers
|
||||
|
||||
internal U64 pe_pdata_off_from_voff__binary_search_x8664(String8 raw_data, U64 voff);
|
||||
internal void * pe_ptr_from_voff(String8 data, PE_BinInfo *bin, U64 voff);
|
||||
internal U64 pe_section_num_from_voff(String8 data, PE_BinInfo *bin, U64 voff);
|
||||
internal void * pe_ptr_from_section_num(String8 data, PE_BinInfo *bin, U64 n);
|
||||
internal U64 pe_foff_from_voff(String8 data, PE_BinInfo *bin, U64 voff);
|
||||
internal PE_BaseRelocBlockList pe_base_reloc_block_list_from_data(Arena *arena, String8 raw_relocs);
|
||||
internal Rng1U64 pe_tls_rng_from_bin_base_vaddr(String8 data, PE_BinInfo *bin, U64 base_vaddr);
|
||||
|
||||
+6
-5
@@ -208,11 +208,12 @@ rc_context_from_cmd_line(Arena *arena, CmdLine *cmdl)
|
||||
}
|
||||
|
||||
if (driver == RC_Driver_Null || driver == RC_Driver_Dwarf) {
|
||||
PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, pe_data);
|
||||
String8 raw_sections = str8_substr(pe_data, rng_1u64(pe.section_array_off, pe.section_array_off+sizeof(COFF_SectionHeader)*pe.section_count));
|
||||
U64 section_count = raw_sections.size / sizeof(COFF_SectionHeader);
|
||||
COFF_SectionHeader *section_array = (COFF_SectionHeader *)raw_sections.str;
|
||||
if (dw_is_dwarf_present_coff_section_table(pe_data, pe.string_table_off, section_count, section_array)) {
|
||||
PE_BinInfo pe = pe_bin_info_from_data(scratch.arena, pe_data);
|
||||
String8 raw_section_table = str8_substr(pe_data, pe.section_table_range);
|
||||
String8 string_table = str8_substr(pe_data, pe.string_table_range);
|
||||
U64 section_count = raw_section_table.size / sizeof(COFF_SectionHeader);
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_section_table.str;
|
||||
if (dw_is_dwarf_present_coff_section_table(pe_data, string_table, section_count, section_table)) {
|
||||
driver = RC_Driver_Dwarf;
|
||||
debug_name = pe_name;
|
||||
debug_data = pe_data;
|
||||
|
||||
@@ -56,7 +56,7 @@ c2r_rdi_binary_section_flags_from_coff_section_flags(COFF_SectionFlags flags)
|
||||
}
|
||||
|
||||
internal RDIM_BinarySectionList
|
||||
c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, U64 string_table_off, U64 sectab_count, COFF_SectionHeader *sectab)
|
||||
c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, String8 string_table, U64 sectab_count, COFF_SectionHeader *sectab)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
|
||||
@@ -66,7 +66,7 @@ c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, U64
|
||||
COFF_SectionHeader *coff_sec = §ab[isec];
|
||||
RDIM_BinarySection *sec = rdim_binary_section_list_push(arena, &binary_sections);
|
||||
|
||||
sec->name = coff_name_from_section_header(image_data, coff_sec, string_table_off);
|
||||
sec->name = coff_name_from_section_header(string_table, coff_sec);
|
||||
sec->flags = c2r_rdi_binary_section_flags_from_coff_section_flags(coff_sec->flags);
|
||||
sec->voff_first = coff_sec->voff;
|
||||
sec->voff_opl = coff_sec->voff + coff_sec->vsize;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
internal RDI_Arch c2r_rdi_arch_from_coff_machine(COFF_MachineType machine);
|
||||
internal RDI_BinarySectionFlags c2r_rdi_binary_section_flags_from_coff_section_flags(COFF_SectionFlags flags);
|
||||
internal RDIM_BinarySectionList c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, U64 string_table_off, U64 sectab_count, COFF_SectionHeader *sectab);
|
||||
internal RDIM_BinarySectionList c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, String8 string_table, U64 sectab_count, COFF_SectionHeader *sectab);
|
||||
|
||||
#endif // RADCON_COFF_H
|
||||
|
||||
|
||||
@@ -1101,15 +1101,16 @@ d2r_convert(Arena *arena, RDIM_LocalState *local_state, RC_Context *in)
|
||||
image_base = pe.image_base;
|
||||
|
||||
// get image sections
|
||||
String8 raw_sections = str8_substr(in->image_data, rng_1u64(pe.section_array_off, pe.section_array_off+sizeof(COFF_SectionHeader)*pe.section_count));
|
||||
String8 raw_sections = str8_substr(in->image_data, pe.section_table_range);
|
||||
U64 section_count = raw_sections.size / sizeof(COFF_SectionHeader);
|
||||
COFF_SectionHeader *section_array = (COFF_SectionHeader *)raw_sections.str;
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_sections.str;
|
||||
|
||||
// convert sections
|
||||
binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, in->image_data, pe.string_table_off, section_count, section_array);
|
||||
String8 string_table = str8_substr(in->image_data, pe.string_table_range);
|
||||
binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, in->image_data, string_table, section_count, section_table);
|
||||
|
||||
// make DWARF input
|
||||
input = dw_input_from_coff_section_table(scratch.arena, in->image_data, pe.string_table_off, section_count, section_array);
|
||||
input = dw_input_from_coff_section_table(scratch.arena, in->image_data, string_table, section_count, section_table);
|
||||
} else if (in->image == Image_Elf32 || in->image == Image_Elf64) {
|
||||
ELF_BinInfo elf = elf_bin_from_data(in->debug_data);
|
||||
|
||||
|
||||
@@ -2366,7 +2366,7 @@ p2r_convert(Arena *arena, RDIM_LocalState *local_state, RC_Context *in)
|
||||
//////////////////////////////////////////////////////////////
|
||||
//- rjf: build binary sections list
|
||||
//
|
||||
RDIM_BinarySectionList binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, str8_zero(), 0, coff_sections.count, coff_sections.v);
|
||||
RDIM_BinarySectionList binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, str8_zero(), str8_zero(), coff_sections.count, coff_sections.v);
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//- rjf: produce top-level-info
|
||||
|
||||
+64
-54
@@ -396,7 +396,7 @@ rd_section_markers_from_rdi(Arena *arena, RDI_Parsed *rdi)
|
||||
}
|
||||
|
||||
internal RD_MarkerArray *
|
||||
rd_section_markers_from_coff_symbol_table(Arena *arena, String8 raw_data, U64 string_table_off, U64 section_count, COFF_Symbol32Array symbols)
|
||||
rd_section_markers_from_coff_symbol_table(Arena *arena, String8 string_table, U64 section_count, COFF_Symbol32Array symbols)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
@@ -411,7 +411,7 @@ rd_section_markers_from_coff_symbol_table(Arena *arena, String8 raw_data, U64 st
|
||||
(symbol->storage_class == COFF_SymStorageClass_External || symbol->storage_class == COFF_SymStorageClass_Static);
|
||||
|
||||
if (is_marker) {
|
||||
String8 name = coff_read_symbol_name(raw_data, string_table_off, &symbol->name);
|
||||
String8 name = coff_read_symbol_name(string_table, &symbol->name);
|
||||
|
||||
RD_MarkerNode *n = push_array(scratch.arena, RD_MarkerNode, 1);
|
||||
n->v.off = symbol->value;
|
||||
@@ -5853,14 +5853,14 @@ cv_print_symbols_section(Arena *arena,
|
||||
}
|
||||
|
||||
internal void
|
||||
cv_format_debug_sections(Arena *arena, String8List *out, String8 indent, String8 raw_image, U64 string_table_off, U64 section_count, COFF_SectionHeader *sections)
|
||||
cv_format_debug_sections(Arena *arena, String8List *out, String8 indent, String8 raw_image, String8 string_table, U64 section_count, COFF_SectionHeader *sections)
|
||||
{
|
||||
CV_Arch arch = ~0;
|
||||
{
|
||||
B32 keep_parsing = 1;
|
||||
for (U64 i = 0; i < section_count && keep_parsing; ++i) {
|
||||
COFF_SectionHeader *header = §ions[i];
|
||||
String8 sect_name = coff_name_from_section_header(raw_image, header, string_table_off);
|
||||
String8 sect_name = coff_name_from_section_header(string_table, header);
|
||||
Rng1U64 sect_frange = rng_1u64(header->foff, header->foff+header->fsize);
|
||||
String8 raw_sect = str8_substr(raw_image, sect_frange);
|
||||
if (str8_match_lit(".debug$S", sect_name, 0)) {
|
||||
@@ -5908,7 +5908,7 @@ cv_format_debug_sections(Arena *arena, String8List *out, String8 indent, String8
|
||||
|
||||
for (U64 i = 0; i < section_count; ++i) {
|
||||
COFF_SectionHeader *header = §ions[i];
|
||||
String8 sect_name = coff_name_from_section_header(raw_image, header, string_table_off);
|
||||
String8 sect_name = coff_name_from_section_header(string_table, header);
|
||||
Rng1U64 sect_frange = rng_1u64(header->foff, header->foff+header->fsize);
|
||||
String8 raw_sect = str8_substr(raw_image, sect_frange);
|
||||
if (str8_match_lit(".debug$S", sect_name, 0)) {
|
||||
@@ -5957,35 +5957,34 @@ coff_print_archive_member_header(Arena *arena, String8List *out, String8 indent,
|
||||
}
|
||||
|
||||
internal void
|
||||
coff_print_seciton_table(Arena *arena,
|
||||
coff_print_section_table(Arena *arena,
|
||||
String8List *out,
|
||||
String8 indent,
|
||||
String8 raw_data,
|
||||
U64 string_table_off,
|
||||
COFF_Symbol32Array symbols,
|
||||
U64 sect_count,
|
||||
COFF_SectionHeader *sect_headers)
|
||||
String8 string_table,
|
||||
COFF_Symbol32Array symbol_table,
|
||||
U64 section_count,
|
||||
COFF_SectionHeader *section_table)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
String8 *symlinks = push_array(scratch.arena, String8, sect_count);
|
||||
for (U64 i = 0; i < symbols.count; ++i) {
|
||||
COFF_Symbol32 *symbol = symbols.v+i;
|
||||
String8 *symlinks = push_array(scratch.arena, String8, section_count);
|
||||
for (U64 i = 0; i < symbol_table.count; ++i) {
|
||||
COFF_Symbol32 *symbol = symbol_table.v+i;
|
||||
COFF_SymbolValueInterpType interp = coff_interp_symbol(symbol->section_number, symbol->value, symbol->storage_class);
|
||||
if (interp == COFF_SymbolValueInterp_Regular &&
|
||||
symbol->aux_symbol_count == 0 &&
|
||||
(symbol->storage_class == COFF_SymStorageClass_External || symbol->storage_class == COFF_SymStorageClass_Static)) {
|
||||
if (symbol->section_number > 0 && symbol->section_number <= symbols.count) {
|
||||
COFF_SectionHeader *header = sect_headers+(symbol->section_number-1);
|
||||
if (symbol->section_number > 0 && symbol->section_number <= symbol_table.count) {
|
||||
COFF_SectionHeader *header = section_table+(symbol->section_number-1);
|
||||
if (header->flags & COFF_SectionFlag_LnkCOMDAT) {
|
||||
symlinks[symbol->section_number-1] = coff_read_symbol_name(raw_data, string_table_off, &symbol->name);
|
||||
symlinks[symbol->section_number-1] = coff_read_symbol_name(string_table, &symbol->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
i += symbol->aux_symbol_count;
|
||||
}
|
||||
|
||||
if (sect_count) {
|
||||
if (section_count) {
|
||||
rd_printf("# Section Table");
|
||||
rd_indent();
|
||||
|
||||
@@ -6004,11 +6003,11 @@ coff_print_seciton_table(Arena *arena,
|
||||
"Flags",
|
||||
"Symlink");
|
||||
|
||||
for (U64 i = 0; i < sect_count; ++i) {
|
||||
COFF_SectionHeader *header = sect_headers+i;
|
||||
for (U64 i = 0; i < section_count; ++i) {
|
||||
COFF_SectionHeader *header = section_table+i;
|
||||
|
||||
String8 name = str8_cstring_capped(header->name, header->name+sizeof(header->name));
|
||||
String8 full_name = coff_name_from_section_header(raw_data, header, string_table_off);
|
||||
String8 full_name = coff_name_from_section_header(string_table, header);
|
||||
|
||||
String8 align;
|
||||
{
|
||||
@@ -6188,13 +6187,13 @@ coff_raw_data_sections(Arena *arena,
|
||||
String8 indent,
|
||||
String8 raw_data,
|
||||
B32 is_obj,
|
||||
RD_MarkerArray *section_markers,
|
||||
RD_MarkerArray *section_markers,
|
||||
U64 section_count,
|
||||
COFF_SectionHeader *sections)
|
||||
COFF_SectionHeader *section_table)
|
||||
{
|
||||
if (section_count) {
|
||||
for (U64 sect_idx = 0; sect_idx < section_count; ++sect_idx) {
|
||||
COFF_SectionHeader *sect = sections+sect_idx;
|
||||
COFF_SectionHeader *sect = section_table+sect_idx;
|
||||
if (sect->fsize > 0) {
|
||||
U64 sect_size = is_obj ? sect->fsize : sect->vsize;
|
||||
String8 raw_sect = str8_substr(raw_data, rng_1u64(sect->foff, sect->foff+sect_size));
|
||||
@@ -6215,7 +6214,7 @@ coff_print_relocs(Arena *arena,
|
||||
String8List *out,
|
||||
String8 indent,
|
||||
String8 raw_data,
|
||||
U64 string_table_off,
|
||||
String8 string_table,
|
||||
COFF_MachineType machine,
|
||||
U64 sect_count,
|
||||
COFF_SectionHeader *sect_headers,
|
||||
@@ -6263,7 +6262,7 @@ coff_print_relocs(Arena *arena,
|
||||
}
|
||||
|
||||
COFF_Symbol32 *symbol = symbols.v+reloc->isymbol;
|
||||
String8 symbol_name = coff_read_symbol_name(raw_data, string_table_off, &symbol->name);
|
||||
String8 symbol_name = coff_read_symbol_name(string_table, &symbol->name);
|
||||
|
||||
String8List line = {0};
|
||||
str8_list_pushf(scratch.arena, &line, "%-4x", reloc_idx );
|
||||
@@ -6294,7 +6293,7 @@ coff_print_symbol_table(Arena *arena,
|
||||
String8 indent,
|
||||
String8 raw_data,
|
||||
B32 is_big_obj,
|
||||
U64 string_table_off,
|
||||
String8 string_table,
|
||||
COFF_Symbol32Array symbols)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
@@ -6308,7 +6307,7 @@ coff_print_symbol_table(Arena *arena,
|
||||
|
||||
for (U64 i = 0; i < symbols.count; ++i) {
|
||||
COFF_Symbol32 *symbol = &symbols.v[i];
|
||||
String8 name = coff_read_symbol_name(raw_data, string_table_off, &symbol->name);
|
||||
String8 name = coff_read_symbol_name(string_table, &symbol->name);
|
||||
String8 msb = coff_string_from_sym_dtype(symbol->type.u.msb);
|
||||
String8 lsb = coff_string_from_sym_type(symbol->type.u.lsb);
|
||||
String8 storage_class = coff_string_from_sym_storage_class(symbol->storage_class);
|
||||
@@ -6460,10 +6459,15 @@ coff_print_big_obj(Arena *arena, String8List *out, String8 indent, String8 raw_d
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
COFF_BigObjHeader *big_obj = str8_deserial_get_raw_ptr(raw_data, 0, sizeof(COFF_BigObjHeader));
|
||||
COFF_SectionHeader *sections = str8_deserial_get_raw_ptr(raw_data, sizeof(COFF_BigObjHeader), sizeof(COFF_SectionHeader)*big_obj->section_count);
|
||||
U64 string_table_off = big_obj->symbol_table_foff + sizeof(COFF_Symbol32)*big_obj->symbol_count;
|
||||
COFF_Symbol32Array symbols = coff_symbol_array_from_data_32(scratch.arena, raw_data, big_obj->symbol_table_foff, big_obj->symbol_count);
|
||||
COFF_FileHeaderInfo header_info = coff_file_header_info_from_data(raw_data);
|
||||
|
||||
String8 raw_header = str8_substr(raw_data, header_info.header_range);
|
||||
String8 raw_section_table = str8_substr(raw_data, header_info.section_table_range);
|
||||
String8 raw_string_table = str8_substr(raw_data, header_info.string_table_range);
|
||||
|
||||
COFF_BigObjHeader *big_obj = (COFF_BigObjHeader *)raw_header.str;
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_section_table.str;
|
||||
COFF_Symbol32Array symbol_table = coff_symbol_array_from_data_32(scratch.arena, raw_data, header_info.symbol_table_range.min, big_obj->symbol_count);
|
||||
|
||||
if (opts & RD_Option_Headers) {
|
||||
coff_print_big_obj_header(arena, out, indent, big_obj);
|
||||
@@ -6490,17 +6494,17 @@ coff_print_big_obj(Arena *arena, String8List *out, String8 indent, String8 raw_d
|
||||
}
|
||||
}
|
||||
|
||||
coff_print_seciton_table(arena, out, indent, raw_data, string_table_off, symbols, big_obj->section_count, sections);
|
||||
coff_print_section_table(arena, out, indent, raw_string_table, symbol_table, big_obj->section_count, section_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Relocs) {
|
||||
coff_print_relocs(arena, out, indent, raw_data, string_table_off, big_obj->machine, big_obj->section_count, sections, symbols);
|
||||
coff_print_relocs(arena, out, indent, raw_data, raw_string_table, big_obj->machine, big_obj->section_count, section_table, symbol_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Symbols) {
|
||||
coff_print_symbol_table(arena, out, indent, raw_data, 1, string_table_off, symbols);
|
||||
coff_print_symbol_table(arena, out, indent, raw_data, 1, raw_string_table, symbol_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
@@ -6513,11 +6517,16 @@ coff_print_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data,
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
|
||||
COFF_FileHeader *header = (COFF_FileHeader *)raw_data.str;
|
||||
COFF_SectionHeader *sections = (COFF_SectionHeader *)(header+1);
|
||||
U64 string_table_off = header->symbol_table_foff + sizeof(COFF_Symbol16)*header->symbol_count;
|
||||
COFF_Symbol32Array symbols = coff_symbol_array_from_data_16(scratch.arena, raw_data, header->symbol_table_foff, header->symbol_count);
|
||||
Arch arch = arch_from_coff_machine(header->machine);
|
||||
COFF_FileHeaderInfo header_info = coff_file_header_info_from_data(raw_data);
|
||||
|
||||
String8 raw_header = str8_substr(raw_data, header_info.header_range);
|
||||
String8 raw_section_table = str8_substr(raw_data, header_info.section_table_range);
|
||||
String8 raw_string_table = str8_substr(raw_data, header_info.string_table_range);
|
||||
|
||||
COFF_FileHeader *header = (COFF_FileHeader *)raw_header.str;
|
||||
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_section_table.str;
|
||||
COFF_Symbol32Array symbol_table = coff_symbol_array_from_data_16(scratch.arena, raw_data, header_info.symbol_table_range.min, header->symbol_count);
|
||||
Arch arch = arch_from_coff_machine(header->machine);
|
||||
|
||||
if (opts & RD_Option_Headers) {
|
||||
coff_print_file_header(arena, out, indent, header);
|
||||
@@ -6544,40 +6553,40 @@ coff_print_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data,
|
||||
}
|
||||
}
|
||||
|
||||
coff_print_seciton_table(arena, out, indent, raw_data, string_table_off, symbols, header->section_count, sections);
|
||||
coff_print_section_table(arena, out, indent, raw_string_table, symbol_table, header->section_count, section_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Relocs) {
|
||||
coff_print_relocs(arena, out, indent, raw_data, string_table_off, header->machine, header->section_count, sections, symbols);
|
||||
coff_print_relocs(arena, out, indent, raw_data, raw_string_table, header->machine, header->section_count, section_table, symbol_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Symbols) {
|
||||
coff_print_symbol_table(arena, out, indent, raw_data, 0, string_table_off, symbols);
|
||||
coff_print_symbol_table(arena, out, indent, raw_data, 0, raw_string_table, symbol_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
RD_MarkerArray *section_markers = 0;
|
||||
if (opts & (RD_Option_Disasm|RD_Option_Rawdata)) {
|
||||
section_markers = rd_section_markers_from_coff_symbol_table(scratch.arena, raw_data, string_table_off, header->section_count, symbols);
|
||||
section_markers = rd_section_markers_from_coff_symbol_table(scratch.arena, raw_string_table, header->section_count, symbol_table);
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Rawdata) {
|
||||
coff_raw_data_sections(arena, out, indent, raw_data, 1, section_markers, header->section_count, sections);
|
||||
coff_raw_data_sections(arena, out, indent, raw_data, 1, section_markers, header->section_count, section_table);
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Disasm) {
|
||||
coff_disasm_sections(arena, out, indent, raw_data, header->machine, 0, 1, section_markers, header->section_count, sections);
|
||||
coff_disasm_sections(arena, out, indent, raw_data, header->machine, 0, 1, section_markers, header->section_count, section_table);
|
||||
rd_newline();
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Codeview) {
|
||||
cv_format_debug_sections(arena, out, indent, raw_data, string_table_off, header->section_count, sections);
|
||||
cv_format_debug_sections(arena, out, indent, raw_data, raw_string_table, header->section_count, section_table);
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Dwarf) {
|
||||
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, string_table_off, header->section_count, sections);
|
||||
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, raw_string_table, header->section_count, section_table);
|
||||
dw_format(arena, out, indent, opts, &dwarf_input, arch, Image_CoffPe);
|
||||
}
|
||||
|
||||
@@ -8109,7 +8118,8 @@ pe_print(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Op
|
||||
goto exit;
|
||||
}
|
||||
|
||||
U64 string_table_off = file_header->symbol_table_foff + sizeof(COFF_Symbol16) * file_header->symbol_count;
|
||||
U64 string_table_off = file_header->symbol_table_foff + sizeof(COFF_Symbol16) * file_header->symbol_count;
|
||||
String8 raw_string_table = str8_substr(raw_data, rng_1u64(string_table_off, raw_data.size));
|
||||
|
||||
COFF_Symbol32Array symbols = coff_symbol_array_from_data_16(scratch.arena, raw_data, file_header->symbol_table_foff, file_header->symbol_count);
|
||||
|
||||
@@ -8165,15 +8175,15 @@ pe_print(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Op
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Sections) {
|
||||
coff_print_seciton_table(arena, out, indent, raw_data, string_table_off, symbols, file_header->section_count, sections);
|
||||
coff_print_section_table(arena, out, indent, raw_string_table, symbols, file_header->section_count, sections);
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Relocs) {
|
||||
coff_print_relocs(arena, out, indent, raw_data, string_table_off, file_header->machine, file_header->section_count, sections, symbols);
|
||||
coff_print_relocs(arena, out, indent, raw_data, raw_string_table, file_header->machine, file_header->section_count, sections, symbols);
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Symbols) {
|
||||
coff_print_symbol_table(arena, out, indent, raw_data, 0, string_table_off, symbols);
|
||||
coff_print_symbol_table(arena, out, indent, raw_data, 0, raw_string_table, symbols);
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Exports) {
|
||||
@@ -8253,7 +8263,7 @@ pe_print(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Op
|
||||
if (rdi) {
|
||||
section_markers = rd_section_markers_from_rdi(scratch.arena, rdi);
|
||||
} else {
|
||||
section_markers = rd_section_markers_from_coff_symbol_table(scratch.arena, raw_data, string_table_off, file_header->section_count, symbols);
|
||||
section_markers = rd_section_markers_from_coff_symbol_table(scratch.arena, raw_string_table, file_header->section_count, symbols);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8266,7 +8276,7 @@ pe_print(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Op
|
||||
}
|
||||
|
||||
if (opts & RD_Option_Dwarf) {
|
||||
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, string_table_off, file_header->section_count, sections);
|
||||
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, raw_string_table, file_header->section_count, sections);
|
||||
dw_format(arena, out, indent, opts, &dwarf_input, arch, Image_CoffPe);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ internal void rd_format_preamble(Arena *arena, String8List *out, String8 indent,
|
||||
|
||||
// Markers
|
||||
|
||||
internal RD_MarkerArray * rd_section_markers_from_coff_symbol_table(Arena *arena, String8 raw_data, U64 string_table_off, U64 section_count, COFF_Symbol32Array symbols);
|
||||
internal RD_MarkerArray * rd_section_markers_from_coff_symbol_table(Arena *arena, String8 string_table, U64 section_count, COFF_Symbol32Array symbols);
|
||||
|
||||
// Sections
|
||||
|
||||
@@ -258,11 +258,11 @@ internal void cv_print_symbols_section(Arena *arena, String8List *out, String8 i
|
||||
// COFF
|
||||
|
||||
internal void coff_print_archive_member_header(Arena *arena, String8List *out, String8 indent, COFF_ParsedArchiveMemberHeader header, String8 long_names);
|
||||
internal void coff_print_seciton_table (Arena *arena, String8List *out, String8 indent, String8 raw_data, U64 string_table_off, COFF_Symbol32Array symbols, U64 sect_count, COFF_SectionHeader *sect_headers);
|
||||
internal void coff_print_section_table (Arena *arena, String8List *out, String8 indent, String8 string_table, COFF_Symbol32Array symbols, U64 sect_count, COFF_SectionHeader *sect_headers);
|
||||
internal void coff_disasm_sections (Arena *arena, String8List *out, String8 indent, String8 raw_data, COFF_MachineType machine, U64 image_base, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal void coff_raw_data_sections (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal void coff_print_relocs (Arena *arena, String8List *out, String8 indent, String8 raw_data, U64 string_table_off, COFF_MachineType machine, U64 sect_count, COFF_SectionHeader *sect_headers, COFF_Symbol32Array symbols);
|
||||
internal void coff_print_symbol_table (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_big_obj, U64 string_table_off, COFF_Symbol32Array symbols);
|
||||
internal void coff_print_relocs (Arena *arena, String8List *out, String8 indent, String8 raw_data, String8 string_table, COFF_MachineType machine, U64 sect_count, COFF_SectionHeader *sect_headers, COFF_Symbol32Array symbols);
|
||||
internal void coff_print_symbol_table (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_big_obj, String8 string_table, COFF_Symbol32Array symbols);
|
||||
internal void coff_print_big_obj_header (Arena *arena, String8List *out, String8 indent, COFF_BigObjHeader *header);
|
||||
internal void coff_print_file_header (Arena *arena, String8List *out, String8 indent, COFF_FileHeader *header);
|
||||
internal void coff_print_import (Arena *arena, String8List *out, String8 indent, COFF_ParsedArchiveImportHeader *header);
|
||||
|
||||
Reference in New Issue
Block a user