COFF symbol fixes for model lang C
authorRobert Pengelly <robertapengelly@hotmail.com>
Thu, 13 Nov 2025 16:53:54 +0000 (16:53 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Thu, 13 Nov 2025 16:53:54 +0000 (16:53 +0000)
as.c
coff.c
intel.c

diff --git a/as.c b/as.c
index 5e4cb64762764ca7f407549a1e19f82d72a83d22..2fcca537897914e03475ec74fa7b79bf03d80fb9 100644 (file)
--- 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 981040cfd75f8142c79974c65638d1419bc4a2e0..8a76a8b10f45816b5ecb9c3bcdd1210569d1464e 100644 (file)
--- 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 43dc8edc7d3f36daecd70aaada12be6674a43d14..19274d5c83f70e45ed7886fb3bee380fb64384ea 100644 (file)
--- 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       },