]> Shamusworld >> Repos - rmac/commitdiff
Fix to prevent defined registers/CCs from being exported in the symtab. v2.2.2
authorShamus Hammons <jlhamm@acm.org>
Mon, 30 May 2022 22:40:19 +0000 (17:40 -0500)
committerShamus Hammons <jlhamm@acm.org>
Mon, 30 May 2022 22:40:19 +0000 (17:40 -0500)
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
object.h
procln.c
procln.h
rmac.c
rmac.h
symbol.c
symbol.h
version.h

index ada5337010c9f371de680c26ef317b6308654a82..31690ae17f85fa57183cc05527e99eeafd12d02e 100644 (file)
--- 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; j<i; j++)
                        extraSyms++;
                }
 
-               int numSymbols = sy_assign_ELF(buf + elfSize, AddELFSymEntry);
+               int numSymbols = AssignSymbolNosELF(buf + elfSize, AddELFSymEntry);
                elfSize += numSymbols * 0x10;
 
                // String table
@@ -823,8 +816,6 @@ for(int j=0; j<i; j++)
                if (buf == NULL)
                        return error("cannot allocate object file memory (in P56/LOD mode)");
 
-//             objImage = buf;                                 // Set global object image pointer
-
                memset(buf, 0, 0x600000);               // Clear allocated memory
 
                // Iterate through DSP ram buffers
@@ -846,9 +837,7 @@ for(int j=0; j<i; j++)
        else if (obj_format == RAW)
        {
                if (!org68k_active)
-               {
                        return error("cannot output absolute binary without a starting address (.org or command line)");
-               }
 
                // Alloc memory for text + data construction.
                tds = sect[TEXT].sloc + sect[DATA].sloc;
@@ -861,9 +850,9 @@ for(int j=0; j<i; j++)
                p = buf;
                objImage = buf;                                 // Set global object image pointer
 
-               for (i = TEXT; i <= DATA; i++)
+               for(i=TEXT; i<=DATA; i++)
                {
-                       for (cp = sect[i].sfcode; cp != NULL; cp = cp->chnext)
+                       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; j<i; j++)
        return 0;
 }
 
-
 static void WriteLOD(void)
 {
        D_printf("_START %s 0000 0000 0000 RMAC %01i.%01i.%01i\n\n", firstfname, MAJOR, MINOR, PATCH);
@@ -958,7 +946,6 @@ static void WriteLOD(void)
        D_printf("\n_END %.4X\n", dsp_orgmap[0].orgadr);
 }
 
-
 static void WriteP56(void)
 {
        for(DSP_ORG * l=&dsp_orgmap[0]; l<dsp_currentorg; l++)
@@ -1024,4 +1011,3 @@ static void WriteP56(void)
                SETBE24(p_buf_len, chunk_size / 3);
        }
 }
-
index 22f17bac110ec45f83a847e17fe6e5313a25ce5e..84d2d601c719aa46c8210894aae770c0478b21ce 100644 (file)
--- a/object.h
+++ b/object.h
@@ -1,7 +1,7 @@
 //
 // RMAC - Renamed Macro Assembler for all Atari computers
 // OBJECT.H - 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
 //
index 4af12bd9000d95ab2001f85534a71c0b1a14670e..52513e0be04f7d42bbc4c7dc77c5f35b2dbbabb8 100644 (file)
--- a/procln.c
+++ b/procln.c
@@ -1,7 +1,7 @@
 //
 // RMAC - Renamed Macro Assembler for all Atari computers
 // PROCLN.C - Line Processing
-// 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
 //
@@ -117,11 +117,9 @@ LONG amsktab[0124] = {
        M_FPSCR                 // 0123
 };                                     // 0123 length
 
-
 // Function prototypes
 int HandleLabel(char *, int);
 
-
 //
 // Initialize line processor
 //
@@ -133,7 +131,6 @@ void InitLineProcessor(void)
        ifent0.if_state = 0;
 }
 
-
 //
 // Line processor
 //
@@ -825,7 +822,6 @@ When checking to see if it's already been equated, issue a warning.
        goto loop;
 }
 
-
 //
 // Handle the creation of labels
 //
@@ -876,4 +872,3 @@ int HandleLabel(char * label, int labelType)
 
        return 0;
 }
-
index 34ba01d8a033c5b7e3edb410c7a1a189e52ec318..abc2c74ba96126b756a06469ec03a5e395967a8a 100644 (file)
--- a/procln.h
+++ b/procln.h
@@ -1,7 +1,7 @@
 //
 // RMAC - Renamed Macro Assembler for all Atari computers
 // PROCLN.H - Line Processing
-// 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
 //
diff --git a/rmac.c b/rmac.c
index 0ae0f6201b9b33c8f3d4f02a4cfd6918da1c9abc..9259d4196aef9b14edf026614d26d38ee0bfeaec 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -1,7 +1,7 @@
 //
 // RMAC - Renamed Macro Assembler for all Atari computers
 // RMAC.C - Main Application Code
-// 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
 //
@@ -30,7 +30,7 @@ int list_pag = 1;                             // Enable listing pagination by default
 int verb_flag;                                 // Be verbose about what's going on
 int m6502;                                             // 1, assembling 6502 code
 int glob_flag;                                 // Assume undefined symbols are global
-int lsym_flag;                                 // Include local symbols in object file
+int lsym_flag;                                 // Include local symbols in object file (ALWAYS true)
 int optim_warn_flag;                   // Warn about possible short branches
 int prg_flag;                                  // !=0, produce .PRG executable (2=symbols)
 int prg_extend;                                        // !=0, output extended .PRG symbols
@@ -221,7 +221,7 @@ void DisplayVersion(void)
                "| |  | | | | | | (_| | (__ \n"
                "|_|  |_| |_| |_|\\__,_|\\___|\n"
                "\nRenamed Macro Assembler\n"
-               "Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends\n"
+               "Copyright (C) 199x Landon Dyer, 2011-2022 Reboot and Friends\n"
                "V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM);
 }
 
diff --git a/rmac.h b/rmac.h
index 44ed972d9e97e4493ea8ea4e7e8d563f7e6b0fcd..0dd9865a512eac30789696a682d94b2684c60c60 100644 (file)
--- a/rmac.h
+++ b/rmac.h
@@ -1,7 +1,7 @@
 //
 // RMAC - Renamed Macro Assembler for all Atari computers
 // RMAC.H - Main Application Code
-// 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
 //
index be9282634f6cace0f44082555dbee8ce142168b3..0a50eeb6c34c77ca39db4371e50fa171fcae7c24 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -1,7 +1,7 @@
 //
 // RMAC - Renamed Macro Assembler for all Atari computers
 // SYMBOL.C - 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
 //
@@ -39,7 +39,6 @@ static uint8_t tdb_text[8] = {
 // Internal function prototypes
 static uint16_t WriteLODSection(int, uint16_t);
 
-
 //
 // Initialize symbol table
 //
@@ -56,7 +55,6 @@ void InitSymbolTable(void)
        currentUID = 0;
 }
 
-
 //
 // Hash the ASCII name and enviroment number
 //
@@ -75,7 +73,6 @@ int HashSymbol(uint8_t * name, int envno)
        return sum & (NBUCKETS - 1);
 }
 
-
 //
 // Make a new symbol of type 'type' in enviroment 'envno'
 //
@@ -121,7 +118,6 @@ SYM * NewSymbol(uint8_t * name, int type, int envno)
        return symbol;
 }
 
-
 //
 // Look up the symbol name by its UID and return the pointer to the name.
 // If it's not found, return NULL.
@@ -146,7 +142,6 @@ uint8_t * GetSymbolNameByUID(uint32_t uid)
        return NULL;
 }
 
-
 //
 // Lookup the symbol 'name', of the specified type, with the specified
 // enviroment level
@@ -171,7 +166,6 @@ SYM * lookup(uint8_t * name, int type, int envno)
        return symbol;
 }
 
-
 //
 // Put symbol on "order-of-declaration" list of symbols
 //
@@ -195,7 +189,6 @@ void AddToSymbolDeclarationList(SYM * symbol)
        sdecltail = symbol;
 }
 
-
 //
 // Make all referenced, undefined symbols global
 //
@@ -215,7 +208,6 @@ void ForceUndefinedSymbolsGlobal(void)
        }
 }
 
-
 //
 // Assign numbers to symbols that are to be exported or imported. The symbol
 // number is put in 'senv'. Returns the number of symbols that will be in the
@@ -226,7 +218,7 @@ void ForceUndefinedSymbolsGlobal(void)
 //       count of the # of symbols in the symbol table, and the second is to
 //       actually create it.
 //
-uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)())
+uint32_t AssignSymbolNos(uint8_t * buf, uint8_t *(* construct)())
 {
        uint16_t scount = 0;
 
@@ -243,10 +235,19 @@ uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)())
        // them. We also pick which symbols should be global or not here.
        for(SYM * sy=sdecl; sy!=NULL; sy=sy->sdecl)
        {
+               // 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;
 }
-
index ddf2d22c07285dac525804a0f612778bb9ff89d7..1a27a6b02736f42a52abe311461bcc1242a4d48a 100644 (file)
--- 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);
 
index f8782caa5853946c5cceb1c2797da083c816ed6e..11a3a177845ee9a9a7187e44e86ae45975ddb27b 100644 (file)
--- 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__