Changed the object file and library format. There is now an additional

string table in the object file that (currently) holds all identifiers
from the import, export and debug info sections. The plan is to put all
strings into this table, so we have them in a central place and don't
waste memory. Apart from that, the indices are unique, so comparing strings
should be a lot easier than before (as soon as the programs take advantage
of this fact, which is currently not the case).


git-svn-id: svn://svn.cc65.org/cc65/trunk@2169 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-05-25 17:57:50 +00:00
parent 487ded2ce2
commit 76e67e2f97
41 changed files with 804 additions and 401 deletions

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<EFBFBD>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -38,7 +38,7 @@
/* common */
#include "hashstr.h"
#include "xmalloc.h"
/* ar65 */
#include "error.h"
#include "objdata.h"
@@ -53,8 +53,8 @@
/* A hash table entry */
typedef struct HashEntry_ HashEntry;
struct HashEntry_ {
typedef struct HashEntry HashEntry;
struct HashEntry {
HashEntry* Next; /* Next in list */
unsigned Module; /* Module index */
char Name [1]; /* Name of identifier */
@@ -149,4 +149,3 @@ int ExpFind (const char* Name)

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<EFBFBD>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -71,7 +71,8 @@ static const char* LibName = 0;
static LibHeader Header = {
LIB_MAGIC,
LIB_VERSION,
0, 0
0,
0
};
@@ -106,6 +107,8 @@ static void ReadHeader (void)
static void ReadIndexEntry (void)
/* Read one entry in the index */
{
unsigned I;
/* Create a new entry and insert it into the list */
ObjData* O = NewObjData ();
@@ -116,13 +119,20 @@ static void ReadIndexEntry (void)
O->Start = Read32 (Lib);
O->Size = Read32 (Lib);
/* Strings */
O->StringCount = ReadVar (Lib);
O->Strings = xmalloc (O->StringCount * sizeof (char*));
for (I = 0; I < O->StringCount; ++I) {
O->Strings[I] = ReadStr (Lib);
}
/* Exports */
O->ExportSize = Read16 (Lib);
O->ExportSize = ReadVar (Lib);
O->Exports = xmalloc (O->ExportSize);
ReadData (Lib, O->Exports, O->ExportSize);
/* Imports */
O->ImportSize = Read16 (Lib);
O->ImportSize = ReadVar (Lib);
O->Imports = xmalloc (O->ImportSize);
ReadData (Lib, O->Imports, O->ImportSize);
}
@@ -138,7 +148,7 @@ static void ReadIndex (void)
fseek (Lib, Header.IndexOffs, SEEK_SET);
/* Read the object file count and calculate the cross ref size */
Count = Read16 (Lib);
Count = ReadVar (Lib);
/* Read all entries in the index */
while (Count--) {
@@ -172,6 +182,8 @@ static void WriteHeader (void)
static void WriteIndexEntry (ObjData* O)
/* Write one index entry */
{
unsigned I;
/* Module name/flags/MTime/start/size */
WriteStr (NewLib, O->Name);
Write16 (NewLib, O->Flags & ~OBJ_HAVEDATA);
@@ -179,12 +191,18 @@ static void WriteIndexEntry (ObjData* O)
Write32 (NewLib, O->Start);
Write32 (NewLib, O->Size);
/* Strings */
WriteVar (NewLib, O->StringCount);
for (I = 0; I < O->StringCount; ++I) {
WriteStr (NewLib, O->Strings[I]);
}
/* Exports */
Write16 (NewLib, O->ExportSize);
WriteVar (NewLib, O->ExportSize);
WriteData (NewLib, O->Exports, O->ExportSize);
/* Imports */
Write16 (NewLib, O->ImportSize);
WriteVar (NewLib, O->ImportSize);
WriteData (NewLib, O->Imports, O->ImportSize);
}
@@ -202,7 +220,7 @@ static void WriteIndex (void)
Header.IndexOffs = ftell (NewLib);
/* Write the object file count */
Write16 (NewLib, ObjCount);
WriteVar (NewLib, ObjCount);
/* Write the object files */
O = ObjRoot;
@@ -348,8 +366,8 @@ static void SkipExpr (unsigned char** Buf)
return;
case EXPR_SYMBOL:
/* 16 bit symbol index */
*Buf += 2;
/* Variable seized symbol index */
(void) GetVar (Buf);
return;
case EXPR_SECTION:
@@ -359,8 +377,8 @@ static void SkipExpr (unsigned char** Buf)
}
/* What's left are unary and binary nodes */
SkipExpr (Buf); /* Skip left */
SkipExpr (Buf); /* Skip right */
SkipExpr (Buf); /* Skip left */
SkipExpr (Buf); /* Skip right */
}
@@ -391,8 +409,7 @@ static void LibCheckExports (ObjData* O)
while (Count--) {
unsigned char Tag;
unsigned Len;
char* Name;
const char* Name;
/* Get the export tag */
Tag = *Exports++;
@@ -400,12 +417,8 @@ static void LibCheckExports (ObjData* O)
/* condes decls may follow */
Exports += GET_EXP_CONDES_COUNT (Tag);
/* Next thing is name of symbol */
Len = GetVar (&Exports);
Name = xmalloc (Len + 1);
memcpy (Name, Exports, Len);
Name [Len] = '\0';
Exports += Len;
/* Next thing is index of name of symbol */
Name = GetObjString (O, GetVar (&Exports));
/* Skip value of symbol */
if (Tag & EXP_EXPR) {
@@ -422,9 +435,6 @@ static void LibCheckExports (ObjData* O)
/* Insert the name into the hash table */
Print (stdout, 1, " %s\n", Name);
ExpInsert (Name, O->Index);
/* Free the name */
xfree (Name);
}
}

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<EFBFBD>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -72,17 +72,19 @@ ObjData* NewObjData (void)
ObjData* O = xmalloc (sizeof (ObjData));
/* Initialize the data */
O->Next = 0;
O->Name = 0;
O->Index = ~0;
O->Flags = 0;
O->MTime = 0;
O->Start = 0;
O->Size = 0;
O->ImportSize = 0;
O->Imports = 0;
O->ExportSize = 0;
O->Exports = 0;
O->Next = 0;
O->Name = 0;
O->Index = ~0;
O->Flags = 0;
O->MTime = 0;
O->Start = 0;
O->Size = 0;
O->StringCount = 0;
O->Strings = 0;
O->ImportSize = 0;
O->Imports = 0;
O->ExportSize = 0;
O->Exports = 0;
/* Link it into the list */
if (ObjLast) {
@@ -105,9 +107,15 @@ ObjData* NewObjData (void)
void FreeObjData (ObjData* O)
/* Free a complete struct */
{
unsigned I;
xfree (O->Name);
xfree (O->Imports);
xfree (O->Exports);
for (I = 0; I < O->StringCount; ++I) {
xfree (O->Strings[I]);
}
xfree (O->Strings);
xfree (O);
}
@@ -189,7 +197,7 @@ void MakeObjPool (void)
/* Set the pool pointer */
ObjPool [Index] = O;
/* Next object */
++Index;
O = O->Next;
@@ -207,5 +215,15 @@ const char* GetObjName (unsigned Index)
const char* GetObjString (const ObjData* O, unsigned Index)
/* Get a string from the string pool of an object file */
{
if (Index >= O->StringCount) {
Error ("Invalid string index (%u) in module `%s'",
Index, GetObjName (O->Index));
}
return O->Strings[Index];
}

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -50,19 +50,21 @@
/* Internal structure holding object file data */
typedef struct ObjData_ ObjData;
struct ObjData_ {
ObjData* Next; /* Linked list of all objects */
char* Name; /* Module name */
unsigned Index; /* Module index */
unsigned Flags;
typedef struct ObjData ObjData;
struct ObjData {
ObjData* Next; /* Linked list of all objects */
char* Name; /* Module name */
unsigned Index; /* Module index */
unsigned Flags;
unsigned long MTime; /* Modifiation time of object file */
unsigned long Start; /* Start offset of data in library */
unsigned long Size; /* Size of data in library */
unsigned StringCount; /* Number of strings */
char** Strings; /* Strings from the object file */
unsigned long ImportSize; /* Size of imports */
void* Imports; /* Imports as raw data */
void* Imports; /* Imports as raw data */
unsigned long ExportSize; /* Size of exports */
void* Exports; /* Exports as raw data */
void* Exports; /* Exports as raw data */
};
@@ -101,6 +103,9 @@ void MakeObjPool (void);
const char* GetObjName (unsigned Index);
/* Get the name of a module by index */
const char* GetObjString (const ObjData* O, unsigned Index);
/* Get a string from the string pool of an object file */
/* End of objdata.h */

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@@ -47,7 +47,7 @@
/* common */
#include "xmalloc.h"
/* ar65 */
#include "error.h"
#include "objdata.h"
@@ -109,6 +109,8 @@ void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
H->DbgSymSize = Read32 (Obj);
H->LineInfoOffs = Read32 (Obj);
H->LineInfoSize = Read32 (Obj);
H->StrPoolOffs = Read32 (Obj);
H->StrPoolSize = Read32 (Obj);
}
@@ -133,6 +135,8 @@ void ObjWriteHeader (FILE* Obj, ObjHeader* H)
Write32 (Obj, H->DbgSymSize);
Write32 (Obj, H->LineInfoOffs);
Write32 (Obj, H->LineInfoSize);
Write32 (Obj, H->StrPoolOffs);
Write32 (Obj, H->StrPoolSize);
}
@@ -144,6 +148,7 @@ void ObjAdd (const char* Name)
const char* Module;
ObjHeader H;
ObjData* O;
unsigned I;
/* Open the object file */
FILE* Obj = fopen (Name, "rb");
@@ -191,6 +196,14 @@ void ObjAdd (const char* Name)
fseek (Obj, H.ExportOffs, SEEK_SET);
ReadData (Obj, O->Exports, O->ExportSize);
/* Read the string pool */
fseek (Obj, H.StrPoolOffs, SEEK_SET);
O->StringCount = ReadVar (Obj);
O->Strings = xmalloc (O->StringCount * sizeof (char*));
for (I = 0; I < O->StringCount; ++I) {
O->Strings[I] = ReadStr (Obj);
}
/* Skip the object file header */
O->Start = ftell (NewLib);
fseek (NewLib, OBJ_HDR_SIZE, SEEK_CUR);
@@ -211,8 +224,9 @@ void ObjAdd (const char* Name)
O->Size = ftell (NewLib) - O->Start;
/* Clear the remaining header fields */
H.ImportOffs = H.ImportSize = 0;
H.ExportOffs = H.ExportSize = 0;
H.ImportOffs = H.ImportSize = 0;
H.ExportOffs = H.ExportSize = 0;
H.StrPoolOffs = H.StrPoolSize = 0;
/* Seek back and write the updated header */
fseek (NewLib, O->Start, SEEK_SET);
@@ -232,10 +246,12 @@ void ObjExtract (const char* Name)
{
unsigned long ImportStart;
unsigned long ExportStart;
unsigned long StrPoolStart;
unsigned long StrPoolSize;
struct utimbuf U;
ObjHeader H;
FILE* Obj;
unsigned I;
/* Make a module name from the file name */
const char* Module = GetModule (Name);
@@ -263,15 +279,25 @@ void ObjExtract (const char* Name)
ExportStart = ftell (Obj);
WriteData (Obj, O->Exports, O->ExportSize);
/* Write the string pool */
StrPoolStart = ftell (Obj);
WriteVar (Obj, O->StringCount);
for (I = 0; I < O->StringCount; ++I) {
WriteStr (Obj, O->Strings[I]);
}
StrPoolSize = ftell (Obj) - StrPoolStart;
/* Seek back and read the header */
fseek (Obj, 0, SEEK_SET);
ObjReadHeader (Obj, &H, Name);
/* Update the header fields */
H.ImportOffs = ImportStart;
H.ImportSize = O->ImportSize;
H.ExportOffs = ExportStart;
H.ExportSize = O->ExportSize;
H.ImportOffs = ImportStart;
H.ImportSize = O->ImportSize;
H.ExportOffs = ExportStart;
H.ExportSize = O->ExportSize;
H.StrPoolOffs = StrPoolStart;
H.StrPoolSize = StrPoolSize;
/* Write the changed header */
fseek (Obj, 0, SEEK_SET);