From d3d5311a71d07f3c6f4d4feeb50d18b11c0591bd Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Thu, 12 Dec 2024 17:58:57 +0000 Subject: [PATCH] Bug fixes --- link.c | 66 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/link.c b/link.c index 2cf0921..879c915 100644 --- a/link.c +++ b/link.c @@ -95,7 +95,7 @@ static void output_symbols () { } -static void generate_symbols_table (unsigned long offset) { +static unsigned long generate_symbols_table (unsigned long offset) { struct section *section = section_find_or_make (".data"); @@ -128,42 +128,12 @@ static void generate_symbols_table (unsigned long offset) { if (!part->content_size) { free (part); - return; + return 0; } - if ((symbol = symbol_find ("__symbol_table_start")) && symbol_is_undefined (symbol)) { - - of = object_file_make (FAKE_LD_FILENAME, 1); - - symbol = of->symbol_arr; - symbol->name = xstrdup ("__symbol_table_start"); - - symbol->section_number = ABSOLUTE_SECTION_NUMBER; - symbol->value = offset; - - symbol_record_external_symbol (symbol); - - } - part->content = xmalloc (part->content_size); - if ((symbol = symbol_find ("__symbol_table_end")) && symbol_is_undefined (symbol)) { - - of = object_file_make (FAKE_LD_FILENAME, 1); - - symbol = of->symbol_arr; - symbol->name = xstrdup ("__symbol_table_end"); - - symbol->section_number = ABSOLUTE_SECTION_NUMBER; - symbol->value = offset + part->content_size; - - symbol_record_external_symbol (symbol); - - } - - section->total_size += part->content_size; - for (of = all_object_files; of; of = of->next) { for (i = 0; i < of->symbol_cnt; i++) { @@ -191,6 +161,7 @@ static void generate_symbols_table (unsigned long offset) { } section_append_section_part (section, part); + return part->content_size; } @@ -588,7 +559,36 @@ void link (void) { offset += part->content_size; } - generate_symbols_table (offset); + if ((symbol = symbol_find ("__symbol_table_start")) && symbol_is_undefined (symbol)) { + + of = object_file_make (FAKE_LD_FILENAME, 1); + + symbol = of->symbol_arr; + symbol->name = xstrdup ("__symbol_table_start"); + + symbol->section_number = ABSOLUTE_SECTION_NUMBER; + symbol->value = offset; + + symbol_record_external_symbol (symbol); + + } + + offset += generate_symbols_table (offset); + calculate_section_sizes_and_rvas (); + + if ((symbol = symbol_find ("__symbol_table_end")) && symbol_is_undefined (symbol)) { + + of = object_file_make (FAKE_LD_FILENAME, 1); + + symbol = of->symbol_arr; + symbol->name = xstrdup ("__symbol_table_end"); + + symbol->section_number = ABSOLUTE_SECTION_NUMBER; + symbol->value = offset; + + symbol_record_external_symbol (symbol); + + } } -- 2.34.1