From: Robert Pengelly Date: Thu, 13 Nov 2025 16:53:54 +0000 (+0000) Subject: COFF symbol fixes for model lang C X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=bf8bd80a16c972a2b99d1c5ec292b216d1b206df;p=sasm.git COFF symbol fixes for model lang C --- diff --git a/as.c b/as.c index 5e4cb64..2fcca53 100644 --- a/as.c +++ b/as.c @@ -16,7 +16,6 @@ struct as_state *state = 0; const char *program_name = 0; -extern void output_binary (FILE *fp); extern void output_coff (FILE *fp); extern void output_elks (FILE *fp); diff --git a/coff.c b/coff.c index 981040c..8a76a8b 100644 --- a/coff.c +++ b/coff.c @@ -293,7 +293,7 @@ void output_coff (FILE *outfile) { struct symbol_table_entry sym_tbl_ent; - unsigned long value = symbol_get_value (symbol); + unsigned long value = symbol_get_value (symbol), name_length = 0; unsigned int section_number = 0; memset (&sym_tbl_ent, 0, sizeof (sym_tbl_ent)); @@ -309,7 +309,10 @@ void output_coff (FILE *outfile) { write_to_byte_array (sym_tbl_ent.Type, (IMAGE_SYM_DTYPE_NULL << 8) | IMAGE_SYM_TYPE_NULL, 2); if (symbol_is_external (symbol) || symbol_is_undefined (symbol)) { + + if (state->ext) { name_length = strlen (state->ext); } sym_tbl_ent.StorageClass[0] = IMAGE_SYM_CLASS_EXTERNAL; + } else if (symbol_is_section_symbol (symbol)) { sym_tbl_ent.StorageClass[0] = IMAGE_SYM_CLASS_STATIC; } else if (symbol_get_section (symbol) == text_section) { @@ -324,8 +327,27 @@ void output_coff (FILE *outfile) { write_to_byte_array (sym_tbl_ent.SectionNumber, section_number, 2); symbol->write_name_to_string_table = 0; - if (strlen (symbol->name) <= 8) { - memcpy (sym_tbl_ent.Name, symbol->name, strlen (symbol->name)); + name_length += strlen (symbol->name); + + if (name_length <= 8) { + + if (symbol_is_external (symbol) || symbol_is_undefined (symbol)) { + + if (state->ext) { + + name_length = strlen (state->ext); + memcpy (sym_tbl_ent.Name, state->ext, name_length); + + } else { + name_length = 0; + } + + memcpy (sym_tbl_ent.Name + name_length, symbol->name, strlen (symbol->name)); + + } else { + memcpy (sym_tbl_ent.Name, symbol->name, name_length); + } + } else { memset (sym_tbl_ent.Name, 0, 4); @@ -378,9 +400,24 @@ void output_coff (FILE *outfile) { if (symbol->write_name_to_string_table) { + if (symbol_is_external (symbol) || symbol_is_undefined (symbol)) { + + if (state->ext) { + + if (fwrite (state->ext, strlen (state->ext), 1, outfile) != 1) { + + report_at (program_name, 0, REPORT_ERROR, "failed to write string table"); + return; + + } + + } + + } + if (fwrite (symbol->name, strlen (symbol->name) + 1, 1, outfile) != 1) { - report_at (NULL, 0, REPORT_ERROR, "failed to write string table!"); + report_at (NULL, 0, REPORT_ERROR, "failed to write string table"); return; } diff --git a/intel.c b/intel.c index 43dc8ed..19274d5 100644 --- a/intel.c +++ b/intel.c @@ -1822,6 +1822,15 @@ static void machine_dependent_set_bits (int new_bits, int cause_fatal_error) { } +static void handler_amd64 (char *start, char **pp) { + + (void) start; + (void) pp; + + machine_dependent_set_march ("generic64"); + +} + static void handler_8086 (char *start, char **pp) { (void) start; @@ -2152,6 +2161,8 @@ static void handler_option (char *start, char **pp) { static struct pseudo_op_entry pseudo_op_table[] = { + { ".amd64", &handler_amd64 }, + { ".8086", &handler_8086 }, { ".8087", &handler_8087 },