Bug fixes
authorRobert Pengelly <robertapengelly@hotmail.com>
Mon, 9 Jun 2025 11:37:37 +0000 (12:37 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Mon, 9 Jun 2025 11:37:37 +0000 (12:37 +0100)
coff.c
link.c
pe.c

diff --git a/coff.c b/coff.c
index fb67c782e4151f9592b1b5f89803a59d1149a935..96b51eef36c19c1b60e2e5cbcd72285a6a3070d5 100644 (file)
--- a/coff.c
+++ b/coff.c
 #include    "section.h"
 #include    "write7x.h"
 
+#define     IMAGE_SYM_ABSOLUTE          -1
+#define     IMAGE_SYM_DEBUG             -2
+
+#define     IMAGE_SYM_UNDEFINED         0
+#define     IMAGE_SYM_CLASS_EXTERNAL    2
+#define     IMAGE_SYM_CLASS_STATIC      3
+
 struct string_table_header {
     unsigned char StringTableSize[4];
 };
@@ -30,8 +37,8 @@ struct symbol_table_entry {
     unsigned char SectionNumber[2];
     unsigned char Type[2];
     
-    unsigned char StorageClass;
-    unsigned char NumberOfAuxSymbols;
+    unsigned char StorageClass[1];
+    unsigned char NumberOfAuxSymbols[1];
 
 };
 
@@ -79,6 +86,10 @@ static void translate_relocation (struct reloc_entry *reloc, struct coff_relocat
             exit (EXIT_FAILURE);
     
     }
+    
+    if (reloc->symbol->section_number == IMAGE_SYM_CLASS_STATIC) {
+        reloc->n_type = reloc->symbol->section_number;
+    }
 
 }
 
@@ -191,12 +202,6 @@ static unsigned long translate_Characteristics_to_section_flags (unsigned long C
 
 }
 
-#define     IMAGE_SYM_ABSOLUTE          -1
-#define     IMAGE_SYM_DEBUG             -2
-
-#define     IMAGE_SYM_UNDEFINED         0
-#define     IMAGE_SYM_CLASS_EXTERNAL    2
-
 void read_coff_object (const char *filename, unsigned char *data, unsigned long data_size) {
 
     struct coff_header *coff_hdr;
@@ -363,6 +368,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         part_p_array[i + 1] = part;
     
     }
+    
     no_syms = array_to_integer (coff_hdr->NumberOfSymbols, 4);
     
     for (i = 0; i < no_syms; i++) {
@@ -461,15 +467,19 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         
         }
         
-        if (coff_symbol->StorageClass == IMAGE_SYM_CLASS_EXTERNAL || section_no == IMAGE_SYM_UNDEFINED) {
+        if (coff_symbol->StorageClass[0] == IMAGE_SYM_CLASS_STATIC) {
+            symbol->n_type = 2;
+        }
+        
+        if (coff_symbol->StorageClass[0] == IMAGE_SYM_CLASS_EXTERNAL || section_no == IMAGE_SYM_UNDEFINED) {
             symbol_record_external_symbol (symbol);
         }
         
-        if (coff_symbol->NumberOfAuxSymbols) {
+        if (coff_symbol->NumberOfAuxSymbols[0]) {
         
             unsigned long j;
             
-            for (j = 0; j < coff_symbol->NumberOfAuxSymbols; j++) {
+            for (j = 0; j < coff_symbol->NumberOfAuxSymbols[0]; j++) {
             
                 symbol = of->symbol_arr + i + 1 + j;
                 
@@ -478,7 +488,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
             
             }
             
-            i += coff_symbol->NumberOfAuxSymbols;
+            i += coff_symbol->NumberOfAuxSymbols[1];
         
         }
     
diff --git a/link.c b/link.c
index 373408f836e09a9e02a932140c31d861341c8a9a..3d72b051609ff88eb381f260fc9ccf6c8adffcc8 100644 (file)
--- a/link.c
+++ b/link.c
@@ -363,12 +363,10 @@ static void reloc_generic (struct section_part *part, struct reloc_entry *rel, s
         
         if (state->format == LD_FORMAT_BIN || state->format == LD_FORMAT_COM) {
         
-            if (!rel->n_ext/* || (symbol->n_type & N_TYPE) == N_BSS || (symbol->n_type & N_TYPE) == N_DATA || (symbol->n_type & N_TYPE) == N_TEXT*/) {
+            if (symbol->section_number != ABSOLUTE_SECTION_NUMBER && !rel->n_ext) {
             
-                /*report_at (__FILE__, __LINE__, REPORT_FATAL_ERROR, "symbol: %s, %lx", symbol->name, ((rel->symbolnum) >> 28));*/
-                
-                if (rel->n_type != 2) {
-                    report_at (program_name, 0, REPORT_ERROR, "%s:(%s+%#lu): segment relocation", part->of->filename, part->section->name, offset);
+                if (rel->n_type != 2 && symbol->n_type != 2) {
+                    report_at (program_name, 0, REPORT_ERROR, "%s:(%s+%#lu): segment relocation");
                 }
             
             }
diff --git a/pe.c b/pe.c
index 1cbd650da05add931ad4a9c1fda7c20a6acc0258..777c4c1b3a1c5e977d24415b81651d3fb79773b7 100644 (file)
--- a/pe.c
+++ b/pe.c
@@ -974,13 +974,14 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     unsigned long offset = 0, offset2 = 0, offset3 = 0;
     int bHeaderName;
     
-    FILE *outfile;
     unsigned long pad_length, pad[2];
+    FILE *outfile;
     
-    struct data_entry data_entry;
-    struct data_descriptor data_descriptor;
-    struct section_descriptor_long section_descriptor_long;
     struct section_descriptor_short section_descriptor_short;
+    struct section_descriptor_long section_descriptor_long;
+    
+    struct data_descriptor data_descriptor;
+    struct data_entry data_entry;
     
     info_list = create_symbol_list (export_names, num_names);
     
@@ -1017,9 +1018,7 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     
     }
     
-    offset += write_data (outfile, "!<arch>\n", 8);
-    
-    offsets[0] = offset;
+    offsets[0] = (offset += write_data (outfile, "!<arch>\n", 8));
     
     fseek (outfile, sizeof (struct ar_header), SEEK_CUR);
     offset2 = ftell (outfile);