Extend the object code format by adding a (currently empty) scope table.

Use the address size for import, export and debug symbols (object code
change).
More changes to support the --memory-model switch and address sizes.


git-svn-id: svn://svn.cc65.org/cc65/trunk@2691 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-11-28 22:12:14 +00:00
parent e3eea961c2
commit 8f9a21ae3f
35 changed files with 589 additions and 254 deletions

View File

@@ -70,7 +70,7 @@ static DbgSym* DbgSymPool[256];
static DbgSym* NewDbgSym (unsigned char Type, ObjData* O)
static DbgSym* NewDbgSym (unsigned char Type, unsigned char AddrSize, ObjData* O)
/* Create a new DbgSym and return it */
{
/* Allocate memory */
@@ -83,6 +83,7 @@ static DbgSym* NewDbgSym (unsigned char Type, ObjData* O)
D->Expr = 0;
D->Name = 0;
D->Type = Type;
D->AddrSize = AddrSize;
/* Return the new entry */
return D;
@@ -139,11 +140,12 @@ static void InsertDbgSym (DbgSym* D, long Val)
DbgSym* ReadDbgSym (FILE* F, ObjData* O)
/* Read a debug symbol from a file, insert and return it */
{
/* Read the type */
/* Read the type and address size */
unsigned char Type = Read8 (F);
unsigned char AddrSize = Read8 (F);
/* Create a new debug symbol */
DbgSym* D = NewDbgSym (Type, O);
DbgSym* D = NewDbgSym (Type, AddrSize, O);
/* Read and assign the name */
D->Name = MakeGlobalStringId (O, ReadVar (F));
@@ -271,3 +273,4 @@ void PrintDbgSymLabels (ObjData* O, FILE* F)

View File

@@ -65,6 +65,7 @@ struct DbgSym {
ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned Name; /* Name */
unsigned char Type; /* Type of symbol */
unsigned char AddrSize; /* Address size of symbol */
};

View File

@@ -7,7 +7,7 @@
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -38,6 +38,7 @@
#include <string.h>
/* common */
#include "addrsize.h"
#include "check.h"
#include "coll.h"
#include "hashstr.h"
@@ -90,12 +91,13 @@ static Export** ExpPool = 0; /* Exports array */
static Export* NewExport (unsigned char Type, unsigned Name, ObjData* Obj);
static Export* NewExport (unsigned char Type, unsigned char AddrSize,
unsigned Name, ObjData* Obj);
/* Create a new export and initialize it */
static Import* NewImport (unsigned char Type, ObjData* Obj)
static Import* NewImport (unsigned char AddrSize, ObjData* Obj)
/* Create a new import and initialize it */
{
/* Allocate memory */
@@ -107,7 +109,7 @@ static Import* NewImport (unsigned char Type, ObjData* Obj)
I->Exp = 0;
I->Name = INVALID_STRING_ID;
I->Flags = 0;
I->Type = Type;
I->AddrSize = AddrSize;
/* Return the new structure */
return I;
@@ -129,7 +131,7 @@ void InsertImport (Import* I)
/* Search through the list in that slot and print matching duplicates */
if (HashTab[Hash] == 0) {
/* The slot is empty, we need to insert a dummy export */
E = HashTab[Hash] = NewExport (0, Name, 0);
E = HashTab[Hash] = NewExport (0, ADDR_SIZE_DEFAULT, Name, 0);
++ExpCount;
} else {
E = HashTab [Hash];
@@ -140,7 +142,7 @@ void InsertImport (Import* I)
}
if (E->Next == 0) {
/* End of list an entry not found, insert a dummy */
E->Next = NewExport (0, Name, 0);
E->Next = NewExport (0, ADDR_SIZE_DEFAULT, Name, 0);
E = E->Next; /* Point to dummy */
++ExpCount; /* One export more */
break;
@@ -189,15 +191,11 @@ Import* ReadImport (FILE* F, ObjData* Obj)
{
Import* I;
/* Read the import type and check it */
unsigned char Type = Read8 (F);
if (Type != IMP_ZP && Type != IMP_ABS) {
Error ("Unknown import type in module `%s': %02X",
GetObjFileName (Obj), Type);
}
/* Read the import address size */
unsigned char AddrSize = Read8 (F);
/* Create a new import */
I = NewImport (Type, Obj);
I = NewImport (AddrSize, Obj);
/* Read the name */
I->Name = MakeGlobalStringId (Obj, ReadVar (F));
@@ -205,6 +203,26 @@ Import* ReadImport (FILE* F, ObjData* Obj)
/* Read the file position */
ReadFilePos (F, &I->Pos);
/* Check the address size */
if (I->AddrSize == ADDR_SIZE_DEFAULT || I->AddrSize > ADDR_SIZE_LONG) {
/* Beware: This function may be called in cases where the object file
* is not read completely into memory. In this case, the file list is
* invalid. Be sure not to access it in this case.
*/
if (ObjHasFiles (I->Obj)) {
Error ("Invalid import size in for `%s', imported from %s(%lu): 0x%02X",
GetString (I->Name),
GetSourceFileName (I->Obj, I->Pos.Name),
I->Pos.Line,
I->AddrSize);
} else {
Error ("Invalid import size in for `%s', imported from %s: 0x%02X",
GetString (I->Name),
GetObjFileName (I->Obj),
I->AddrSize);
}
}
/* Return the new import */
return I;
}
@@ -217,7 +235,8 @@ Import* ReadImport (FILE* F, ObjData* Obj)
static Export* NewExport (unsigned char Type, unsigned Name, ObjData* Obj)
static Export* NewExport (unsigned char Type, unsigned char AddrSize,
unsigned Name, ObjData* Obj)
/* Create a new export and initialize it */
{
/* Allocate memory */
@@ -232,6 +251,7 @@ static Export* NewExport (unsigned char Type, unsigned Name, ObjData* Obj)
E->ImpList = 0;
E->Expr = 0;
E->Type = Type;
E->AddrSize = AddrSize;
memset (E->ConDes, 0, sizeof (E->ConDes));
/* Return the new entry */
@@ -335,15 +355,17 @@ void InsertExport (Export* E)
Export* ReadExport (FILE* F, ObjData* O)
/* Read an export from a file */
{
unsigned char Type;
unsigned ConDesCount;
Export* E;
/* Read the type */
Type = Read8 (F);
unsigned char Type = Read8 (F);
/* Read the address size */
unsigned char AddrSize = Read8 (F);
/* Create a new export without a name */
E = NewExport (Type, INVALID_STRING_ID, O);
E = NewExport (Type, AddrSize, INVALID_STRING_ID, O);
/* Read the constructor/destructor decls if we have any */
ConDesCount = GET_EXP_CONDES_COUNT (Type);
@@ -391,7 +413,7 @@ Export* CreateConstExport (unsigned Name, long Value)
/* Create an export for a literal date */
{
/* Create a new export */
Export* E = NewExport (EXP_ABS | EXP_CONST | EXP_EQUATE, Name, 0);
Export* E = NewExport (EXP_CONST | EXP_EQUATE, ADDR_SIZE_ABS, Name, 0);
/* Assign the value */
E->Expr = LiteralExpr (Value, 0);
@@ -409,7 +431,7 @@ Export* CreateMemoryExport (unsigned Name, Memory* Mem, unsigned long Offs)
/* Create an relative export for a memory area offset */
{
/* Create a new export */
Export* E = NewExport (EXP_ABS | EXP_EXPR | EXP_LABEL, Name, 0);
Export* E = NewExport (EXP_EXPR | EXP_LABEL, ADDR_SIZE_ABS, Name, 0);
/* Assign the value */
E->Expr = MemoryExpr (Mem, Offs, 0);
@@ -427,7 +449,7 @@ Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs)
/* Create a relative export to a segment */
{
/* Create a new export */
Export* E = NewExport (EXP_ABS | EXP_EXPR | EXP_LABEL, Name, 0);
Export* E = NewExport (EXP_EXPR | EXP_LABEL, Seg->AddrSize, Name, 0);
/* Assign the value */
E->Expr = SegmentExpr (Seg, Offs, 0);
@@ -445,7 +467,7 @@ Export* CreateSectionExport (unsigned Name, Section* Sec, unsigned long Offs)
/* Create a relative export to a section */
{
/* Create a new export */
Export* E = NewExport (EXP_ABS | EXP_EXPR | EXP_LABEL, Name, 0);
Export* E = NewExport (EXP_EXPR | EXP_LABEL, Sec->AddrSize, Name, 0);
/* Assign the value */
E->Expr = SectionExpr (Sec, Offs, 0);
@@ -529,13 +551,12 @@ static void CheckSymType (const Export* E)
{
/* External with matching imports */
Import* Imp = E->ImpList;
int ZP = IS_EXP_ZP (E->Type);
while (Imp) {
if (ZP != IS_IMP_ZP (Imp->Type)) {
if (E->AddrSize != Imp->AddrSize) {
/* Export is ZP, import is abs or the other way round */
if (E->Obj) {
/* User defined export */
Warning ("Type mismatch for `%s', export in "
Warning ("Address size mismatch for `%s', export in "
"%s(%lu), import in %s(%lu)",
GetString (E->Name),
GetSourceFileName (E->Obj, E->Pos.Name),
@@ -544,7 +565,7 @@ static void CheckSymType (const Export* E)
Imp->Pos.Line);
} else {
/* Export created by the linker */
Warning ("Type mismatch for `%s', imported from %s(%lu)",
Warning ("Address size mismatch for `%s', imported from %s(%lu)",
GetString (E->Name),
GetSourceFileName (Imp->Obj, Imp->Pos.Name),
Imp->Pos.Line);
@@ -656,6 +677,21 @@ void CheckExports (ExpCheckFunc F, void* Data)
static char GetAddrSizeCode (unsigned char AddrSize)
/* Get a one char code for the address size */
{
switch (AddrSize) {
case ADDR_SIZE_ZP: return 'Z';
case ADDR_SIZE_ABS: return 'A';
case ADDR_SIZE_FAR: return 'F';
case ADDR_SIZE_LONG: return 'L';
default:
Internal ("Invalid address size: %u", AddrSize);
}
}
void PrintExportMap (FILE* F)
/* Print an export map to the given file */
{
@@ -675,7 +711,7 @@ void PrintExportMap (FILE* F)
GetExportVal (E),
E->ImpCount? 'R' : ' ',
IS_EXP_LABEL (E->Type)? 'L' : 'E',
IS_EXP_ZP (E->Type)? 'Z' : ' ',
GetAddrSizeCode (E->AddrSize),
IS_EXP_CONDES (E->Type)? 'I' : ' ');
if (++Count == 2) {
Count = 0;

View File

@@ -7,7 +7,7 @@
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -66,7 +66,7 @@ struct Import {
struct Export* Exp; /* Matching export for this import */
unsigned Name; /* Name if not in table */
unsigned char Flags; /* Generic flags */
unsigned char Type; /* Type of import */
unsigned char AddrSize; /* Address size of import */
};
@@ -83,6 +83,7 @@ struct Export {
FilePos Pos; /* File position of definition */
ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned char Type; /* Type of export */
unsigned char AddrSize; /* Address size of export */
unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */
};
@@ -188,7 +189,7 @@ void CircularRefError (const Export* E);
/* End of exports.h */
#endif

View File

@@ -1,13 +1,13 @@
/*****************************************************************************/
/* */
/* */
/* library.c */
/* */
/* */
/* Library data structures and helpers for the ld65 linker */
/* */
/* */
/* */
/* */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -107,6 +107,8 @@ static void LibReadObjHeader (ObjData* O, const char* LibName)
O->Header.StrPoolSize = Read32 (Lib);
O->Header.AssertOffs = Read32 (Lib);
O->Header.AssertSize = Read32 (Lib);
O->Header.ScopeOffs = Read32 (Lib);
O->Header.ScopeSize = Read32 (Lib);
}
@@ -261,6 +263,9 @@ void LibAdd (FILE* F, const char* Name)
/* Read the assertions from the object file */
ObjReadAssertions (Lib, O->Start + O->Header.AssertOffs, O);
/* Read the scope table from the object file */
ObjReadScopes (Lib, O->Start + O->Header.ScopeOffs, O);
/* Seek to the start of the segment list and read the segments.
* This must be last, since the data here may reference other
* stuff.

View File

@@ -90,6 +90,8 @@ ObjData* NewObjData (void)
O->Strings = 0;
O->AssertionCount = 0;
O->Assertions = 0;
O->ScopeCount = 0;
O->Scopes = 0;
/* Return the new entry */
return O;
@@ -192,8 +194,10 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index)
/* Check the parameter */
if (Index >= O->FileCount) {
Error ("Invalid file index (%u) in module `%s' (input file corrupt?)",
/* Error() will terminate the program */
Warning ("Invalid file index (%u) in module `%s' (input file corrupt?)",
Index, GetObjFileName (O));
return "[invalid]"; /* ### */
}
/* Return the name */

View File

@@ -7,7 +7,7 @@
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -40,6 +40,7 @@
/* common */
#include "coll.h"
#include "inline.h"
#include "objdefs.h"
@@ -61,7 +62,7 @@ struct ObjData {
unsigned LibName; /* Name of library */
unsigned long MTime; /* Time of last modification */
ObjHeader Header; /* Header of file */
unsigned long Start; /* Start offset of data in library */
unsigned long Start; /* Start offset of data in library */
unsigned Flags;
unsigned FileCount; /* Input file count */
struct FileInfo** Files; /* List of input files */
@@ -79,6 +80,8 @@ struct ObjData {
unsigned* Strings; /* List of global string indices */
unsigned AssertionCount; /* Count of module assertions */
struct Assertion** Assertions; /* List of module assertions */
unsigned ScopeCount; /* Count of scopes */
struct Scope** Scopes; /* List of scopes */
};
@@ -124,6 +127,16 @@ const char* GetObjFileName (const ObjData* O);
* file is NULL.
*/
#if defined(HAVE_INLINE)
INLINE int ObjHasFiles (const ObjData* O)
/* Return true if the files list does exist */
{
return (O != 0 && O->Files != 0);
}
#else
# defined ObjHasFiles(O) ((O) != 0 && (O)->Files != 0)
#endif
const char* GetSourceFileName (const ObjData* O, unsigned Index);
/* Get the name of the source file with the given index. If O is NULL, return
* "[linker generated]" as the file name.

View File

@@ -7,7 +7,7 @@
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -104,6 +104,8 @@ static void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
H->StrPoolSize = Read32 (Obj);
H->AssertOffs = Read32 (Obj);
H->AssertSize = Read32 (Obj);
H->ScopeOffs = Read32 (Obj);
H->ScopeSize = Read32 (Obj);
}
@@ -252,6 +254,24 @@ void ObjReadAssertions (FILE* F, unsigned long Pos, ObjData* O)
void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O)
/* Read the scope table from a file at the given offset */
{
unsigned I;
/* Seek to the correct position */
FileSetPos (F, Pos);
/* Read the data */
O->ScopeCount = ReadVar (F);
O->Scopes = xmalloc (O->ScopeCount * sizeof (O->Scopes[0]));
for (I = 0; I < O->ScopeCount; ++I) {
O->Scopes[I] = 0; /* ReadScope (F, O); ### not implemented */
}
}
void ObjAdd (FILE* Obj, const char* Name)
/* Add an object file to the module list */
{
@@ -288,6 +308,9 @@ void ObjAdd (FILE* Obj, const char* Name)
/* Read the assertions from the object file */
ObjReadAssertions (Obj, O->Header.AssertOffs, O);
/* Read the scope table from the object file */
ObjReadScopes (Obj, O->Header.ScopeOffs, O);
/* Read the segment list from the object file. This must be last, since
* the expressions stored in the code may reference segments or imported
* symbols.

View File

@@ -7,7 +7,7 @@
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@@ -78,6 +78,9 @@ void ObjReadStrPool (FILE* F, unsigned long Pos, ObjData* O);
void ObjReadAssertions (FILE* F, unsigned long Pos, ObjData* O);
/* Read the assertions from a file at the given offset */
void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O);
/* Read the scope table from a file at the given offset */
void ObjAdd (FILE* F, const char* Name);
/* Add an object file to the module list */