From 9ad657eec68882f88dbce18d4a62c676ec8a4fa8 Mon Sep 17 00:00:00 2001 From: ggn Date: Tue, 1 Sep 2020 17:59:44 +0300 Subject: [PATCH] Fix for bug #168 - when COFF output is requested and no symbol switches are active, fill the header symbol fileds with zeros --- rln.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rln.c b/rln.c index 482330a..7afb236 100644 --- a/rln.c +++ b/rln.c @@ -307,6 +307,9 @@ int DoSymbols(struct OFILE * ofile) } } + if (vflag > 2) + printf("DoSymbols: Symbol: %s type=%08X val=%08X\n", symend + index, type, value); + // Add to output symbol table if global/extern, or local flag is set if (isglobal(type) || lflag) { @@ -1120,6 +1123,10 @@ int WriteOutputFile(struct OHEADER * header) bsoff += otemp->segSize[TEXT] + otemp->segSize[DATA]; } + uint32_t symbol_offset = 0; + if (sflag || lflag) + symbol_offset = dsoff + header->dsize; + // Currently this only builds a COF absolute file. Conditionals and // additional code will need to be added for ABS and partial linking. @@ -1127,7 +1134,7 @@ int WriteOutputFile(struct OHEADER * header) PutWord(himage + 0, 0x0150 ); // Magic Number (0x0150) PutWord(himage + 2, 0x0003 ); // Sections Number (3) PutLong(himage + 4, 0x00000000 ); // Date (0L) - PutLong(himage + 8, dsoff + header->dsize); // Offset to Symbols Section + PutLong(himage + 8, symbol_offset ); // Offset to Symbols Section PutLong(himage + 12, ost_index); // Number of Symbols PutWord(himage + 16, 0x001C ); // Size of RUN_HDR (0x1C) PutWord(himage + 18, 0x0003 ); // Executable Flags (3) @@ -1584,9 +1591,13 @@ struct OHEADER * MakeOutputObject() } // Inject segment end labels, for C compilers that expect this shite - OSTAdd("_TEXT_E", 0x05000000, tbase + textsize); - OSTAdd("_DATA_E", 0x07000000, dbase + datasize); - OSTAdd("_BSS_E", 0x09000000, bbase + bsssize); + // Exception: if user requested no debug symbols. No reason to add anything then + if (sflag || lflag) + { + OSTAdd("_TEXT_E", 0x05000000, tbase + textsize); + OSTAdd("_DATA_E", 0x07000000, dbase + datasize); + OSTAdd("_BSS_E", 0x09000000, bbase + bsssize); + } // Place each unresolved symbol in the output symbol table // N.B.: It only gets here to do this if user passes in -u flag -- 2.25.0.windows.1