From 2e6a046d5d7e2c1863179c4dce8ef7505ff6dd6c Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 30 May 2022 17:40:19 -0500 Subject: [PATCH] Fix to prevent defined registers/CCs from being exported in the symtab. As it turns out, this was not due to malice but because RMAC was set up to squeeze out every label ever defined in the assembly. Hopefully, with this patch, things should be a bit more sane. :-) --- object.c | 40 +++++++++++++--------------------------- object.h | 2 +- procln.c | 7 +------ procln.h | 2 +- rmac.c | 6 +++--- rmac.h | 2 +- symbol.c | 52 +++++++++++++++++++++++++--------------------------- symbol.h | 6 +++--- version.h | 2 +- 9 files changed, 49 insertions(+), 70 deletions(-) diff --git a/object.c b/object.c index ada5337..31690ae 100644 --- a/object.c +++ b/object.c @@ -1,7 +1,7 @@ // // RMAC - Renamed Macro Assembler for all Atari computers // OBJECT.C - Writing Object Files -// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2022 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -62,7 +62,6 @@ See left. 4 & 5 If these bits are set to 0 (PF_PRIVATE), the processes' static void WriteLOD(void); static void WriteP56(void); - // // Add entry to symbol table (in ALCYON mode) // If 'globflag' is 1, make the symbol global @@ -157,7 +156,6 @@ uint8_t * AddSymEntry(register uint8_t * buf, SYM * sym, int globflag) return buf; } - // // Add an entry to the BSD symbol table // @@ -192,9 +190,9 @@ uint8_t * AddBSDSymEntry(uint8_t * buf, SYM * sym, int globflag) z = 0x02000000; // Set equated flag } - // If a symbol is both EQUd and flagged as TBD then we let - // the later take precedence. Otherwise the linker will not even - // bother trying to relocate the address during link time + // If a symbol is both EQUd and flagged as TBD then we let the latter take + // precedence. Otherwise the linker will not even bother trying to relocate + // the address during link time. switch (w1 & TDB) { @@ -224,7 +222,6 @@ uint8_t * AddBSDSymEntry(uint8_t * buf, SYM * sym, int globflag) return buf; } - // // Add entry to ELF symbol table; if `globflag' is 1, make the symbol global // @@ -275,7 +272,6 @@ uint8_t * AddELFSymEntry(uint8_t * buf, SYM * sym, int globflag) return buf + 0x10; } - // // Helper function for ELF output // @@ -296,7 +292,6 @@ int DepositELFSectionHeader(uint8_t * ptr, uint32_t name, uint32_t type, uint32_ return 40; } - // // Deposit an entry in the Section Header string table // @@ -311,7 +306,6 @@ printf("DepositELFSHSTEntry: s = \"%s\"\n", s); return strSize + 1; } - // // Deposit a symbol table entry in the ELF Symbol Table // @@ -328,7 +322,6 @@ uint32_t DepositELFSymbol(uint8_t * ptr, uint32_t name, uint32_t addr, uint32_t return 16; } - // // Write an object file to the passed in file descriptor // N.B.: Return value is ignored... @@ -363,9 +356,9 @@ int WriteObject(int fd) printf("Total : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc); } - sy_assign(NULL, NULL); // Assign index numbers to the symbols + AssignSymbolNos(NULL, NULL); // Assign index numbers to the symbols tds = sect[TEXT].sloc + sect[DATA].sloc; // Get size of TEXT and DATA segment - buf = malloc(0x800000); // Allocate 8MB object file image memory + buf = malloc(0x800000); // Allocate 8MB object file image memory if (buf == NULL) { @@ -425,7 +418,7 @@ int WriteObject(int fd) // Point to start of symbol table p = buf + BSDHDRSIZE + tds + trsize + drsize; - sy_assign(p, AddBSDSymEntry); // Build symbol and string tables + AssignSymbolNos(p, AddBSDSymEntry); // Build symbol and string tables chptr = buf + 0x10; // Point to sym table size hdr entry D_long(symsize); // Write the symbol table size @@ -465,7 +458,7 @@ int WriteObject(int fd) // Assign index numbers to the symbols, get # of symbols (we assume // that all symbols can potentially be extended, hence the x28) // (To clarify: 28 bytes is the size of an extended symbol) - uint32_t symbolMaxSize = sy_assign(NULL, NULL) * 28; + uint32_t symbolMaxSize = AssignSymbolNos(NULL, NULL) * 28; // Alloc memory for header + text + data, symbol and relocation // information construction. @@ -505,8 +498,8 @@ int WriteObject(int fd) // Construct symbol table and update the header entry, if necessary if (prg_flag > 1) { - // sy_assign with AddSymEntry updates symsize (stays 0 otherwise) - sy_assign(buf + HDRSIZE + tds, AddSymEntry); + // AssignSymbolNos with AddSymEntry updates symsize (stays 0 otherwise) + AssignSymbolNos(buf + HDRSIZE + tds, AddSymEntry); chptr = buf + 0x0E; // Point to symbol table size entry D_long(symsize); @@ -762,7 +755,7 @@ for(int j=0; jchnext) + for(cp=sect[i].sfcode; cp!=NULL; cp=cp->chnext) { memcpy(p, cp->chptr, cp->ch_size); p += cp->ch_size; @@ -886,7 +875,6 @@ for(int j=0; jsdecl) { + // Skip non-labels + if (sy->stype != LABEL) + continue; + + // Nuke equated register/CC symbols from orbit: + if (sy->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC)) + continue; + // Export or import external references, and export COMMON blocks. - if ((sy->stype == LABEL) - && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED) - || (sy->sattr & (GLOBAL | REFERENCED)) == (GLOBAL | REFERENCED)) + // N.B.: This says to mark the symbol as global if either 1) the symbol + // is global AND the symbol is defined OR referenced, or 2) this + // symbol is a common symbol. + if (((sy->sattr & GLOBAL) && (sy->sattr & (DEFINED | REFERENCED))) || (sy->sattr & COMMON)) { sy->senv = scount++; @@ -256,8 +257,11 @@ uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)()) } // Export vanilla labels (but don't make them global). An exception is // made for equates, which are not exported unless they are referenced. - else if (sy->stype == LABEL && lsym_flag - && (sy->sattr & (DEFINED | REFERENCED)) != 0) + // ^^^ The above just might be bullshit. ^^^ + // N.B.: This says if the symbol is either defined OR referenced (but + // because of the above we know it *won't* be GLOBAL). And + // lsym_flag is always set true in Process() in rmac.c. + else if (lsym_flag && (sy->sattr & (DEFINED | REFERENCED))) { sy->senv = scount++; @@ -269,16 +273,15 @@ uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)()) return scount; } - // -// Custom version of sy_assign for ELF .o files. +// Custom version of AssignSymbolNos for ELF .o files. // The order that the symbols should be dumped is different. // (globals must be explicitly at the end of the table) // -// N.B.: It should be possible to merge this with sy_assign, as there's nothing -// really ELF specific in here, other than the "globals go at the end of -// the queue" thing, which doesn't break the others. :-P -uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)()) +// N.B.: It should be possible to merge this with AssignSymbolNos, as there's +// nothing really ELF specific in here, other than the "globals go at the +// end of the queue" thing, which doesn't break the others. :-P +uint32_t AssignSymbolNosELF(uint8_t * buf, uint8_t *(* construct)()) { uint16_t scount = 0; @@ -327,7 +330,7 @@ uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)()) } else if ((sy->sattr == (GLOBAL | REFERENCED)) && (buf != NULL) && (sy->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC)) == 0) { - buf = construct(buf, sy, 0); + buf = construct(buf, sy, 0); // <-- this creates a NON-global symbol... scount++; } } @@ -335,7 +338,6 @@ uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)()) return scount; } - // // Helper function for dsp_lod_symbols // @@ -359,7 +361,6 @@ static uint16_t WriteLODSection(int section, uint16_t symbolCount) return symbolCount; } - // // Dump LOD style symbols into the passed in buffer // @@ -382,7 +383,6 @@ void DumpLODSymbols(void) //WriteLODSection(M56001?, count); } - // // Convert string to uppercase // @@ -395,7 +395,6 @@ void ToUppercase(uint8_t * s) } } - // // Generate symbol table for listing file // @@ -548,4 +547,3 @@ int symtable(void) return 0; } - diff --git a/symbol.h b/symbol.h index ddf2d22..1a27a6b 100644 --- a/symbol.h +++ b/symbol.h @@ -1,7 +1,7 @@ // // RMAC - Renamed Macro Assembler for all Atari computers // SYMBOL.H - Symbol Handling -// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2022 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -50,8 +50,8 @@ SYM * NewSymbol(uint8_t *, int, int); void AddToSymbolDeclarationList(SYM *); void ForceUndefinedSymbolsGlobal(void); int symtable(void); -uint32_t sy_assign(uint8_t *, uint8_t *(*)()); -uint32_t sy_assign_ELF(uint8_t *, uint8_t *(*)()); +uint32_t AssignSymbolNos(uint8_t *, uint8_t *(*)()); +uint32_t AssignSymbolNosELF(uint8_t *, uint8_t *(*)()); void DumpLODSymbols(void); uint8_t * GetSymbolNameByUID(uint32_t); diff --git a/version.h b/version.h index f8782ca..11a3a17 100644 --- a/version.h +++ b/version.h @@ -15,6 +15,6 @@ #define MAJOR 2 // Major version number #define MINOR 2 // Minor version number -#define PATCH 1 // Patch release number +#define PATCH 2 // Patch release number #endif // __VERSION_H__ -- 2.37.2