mirror of
https://github.com/cc65/cc65.git
synced 2025-08-08 06:25:17 +00:00
Adapted to new library format.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4946 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -198,7 +198,8 @@ unsigned Read8 (FILE* F)
|
|||||||
{
|
{
|
||||||
int C = getc (F);
|
int C = getc (F);
|
||||||
if (C == EOF) {
|
if (C == EOF) {
|
||||||
Error ("Read error (file corrupt?)");
|
long Pos = ftell (F);
|
||||||
|
Error ("Read error at position %ld (file corrupt?)", Pos);
|
||||||
}
|
}
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
@@ -325,7 +326,8 @@ void* ReadData (FILE* F, void* Data, unsigned Size)
|
|||||||
/* Explicitly allow reading zero bytes */
|
/* Explicitly allow reading zero bytes */
|
||||||
if (Size > 0) {
|
if (Size > 0) {
|
||||||
if (fread (Data, 1, Size, F) != Size) {
|
if (fread (Data, 1, Size, F) != Size) {
|
||||||
Error ("Read error (file corrupt?)");
|
long Pos = ftell (F);
|
||||||
|
Error ("Read error at position %ld (file corrupt?)", Pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Data;
|
return Data;
|
||||||
|
@@ -197,6 +197,9 @@ static ObjData* ReadIndexEntry (Library* L)
|
|||||||
/* Create a new entry and insert it into the list */
|
/* Create a new entry and insert it into the list */
|
||||||
ObjData* O = NewObjData ();
|
ObjData* O = NewObjData ();
|
||||||
|
|
||||||
|
/* Remember from which library this module is */
|
||||||
|
O->LibName = L->Name;
|
||||||
|
|
||||||
/* Module name */
|
/* Module name */
|
||||||
O->Name = ReadStr (L->F);
|
O->Name = ReadStr (L->F);
|
||||||
|
|
||||||
@@ -206,27 +209,43 @@ static ObjData* ReadIndexEntry (Library* L)
|
|||||||
O->Start = Read32 (L->F);
|
O->Start = Read32 (L->F);
|
||||||
Read32 (L->F); /* Skip Size */
|
Read32 (L->F); /* Skip Size */
|
||||||
|
|
||||||
/* Read the string pool */
|
|
||||||
ObjReadStrPool (L->F, FileGetPos (L->F), O);
|
|
||||||
|
|
||||||
/* Skip the import size, then read the imports */
|
|
||||||
(void) ReadVar (L->F);
|
|
||||||
ObjReadImports (L->F, FileGetPos (L->F), O);
|
|
||||||
|
|
||||||
/* Skip the export size, then read the exports */
|
|
||||||
(void) ReadVar (L->F);
|
|
||||||
ObjReadExports (L->F, FileGetPos (L->F), O);
|
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
return O;
|
return O;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void ReadBasicData (Library* L, ObjData* O)
|
||||||
|
/* Read basic data for an object file that is necessary to resolve external
|
||||||
|
* references.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Seek to the start of the object file and read the header */
|
||||||
|
LibSeek (L, O->Start);
|
||||||
|
LibReadObjHeader (L, O);
|
||||||
|
|
||||||
|
/* Read the string pool */
|
||||||
|
ObjReadStrPool (L->F, O->Start + O->Header.StrPoolOffs, O);
|
||||||
|
|
||||||
|
/* Read the files list */
|
||||||
|
ObjReadFiles (L->F, O->Start + O->Header.FileOffs, O);
|
||||||
|
|
||||||
|
/* Read the line infos */
|
||||||
|
ObjReadLineInfos (L->F, O->Start + O->Header.LineInfoOffs, O);
|
||||||
|
|
||||||
|
/* Read the imports */
|
||||||
|
ObjReadImports (L->F, O->Start + O->Header.ImportOffs, O);
|
||||||
|
|
||||||
|
/* Read the exports */
|
||||||
|
ObjReadExports (L->F, O->Start + O->Header.ExportOffs, O);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void LibReadIndex (Library* L)
|
static void LibReadIndex (Library* L)
|
||||||
/* Read the index of a library file */
|
/* Read the index of a library file */
|
||||||
{
|
{
|
||||||
unsigned ModuleCount;
|
unsigned ModuleCount, I;
|
||||||
|
|
||||||
/* Seek to the start of the index */
|
/* Seek to the start of the index */
|
||||||
LibSeek (L, L->Header.IndexOffs);
|
LibSeek (L, L->Header.IndexOffs);
|
||||||
@@ -239,6 +258,13 @@ static void LibReadIndex (Library* L)
|
|||||||
while (ModuleCount--) {
|
while (ModuleCount--) {
|
||||||
CollAppend (&L->Modules, ReadIndexEntry (L));
|
CollAppend (&L->Modules, ReadIndexEntry (L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Walk over the index and read basic data for all object files in the
|
||||||
|
* library.
|
||||||
|
*/
|
||||||
|
for (I = 0; I < CollCount (&L->Modules); ++I) {
|
||||||
|
ReadBasicData (L, CollAtUnchecked (&L->Modules, I));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -349,19 +375,9 @@ static void LibResolve (void)
|
|||||||
/* Is this object file referenced? */
|
/* Is this object file referenced? */
|
||||||
if (O->Flags & OBJ_REF) {
|
if (O->Flags & OBJ_REF) {
|
||||||
|
|
||||||
/* Seek to the start of the object file and read the header */
|
|
||||||
LibSeek (L, O->Start);
|
|
||||||
LibReadObjHeader (L, O);
|
|
||||||
|
|
||||||
/* Seek to the start of the files list and read the files list */
|
|
||||||
ObjReadFiles (L->F, O->Start + O->Header.FileOffs, O);
|
|
||||||
|
|
||||||
/* Seek to the start of the debug info and read the debug info */
|
/* Seek to the start of the debug info and read the debug info */
|
||||||
ObjReadDbgSyms (L->F, O->Start + O->Header.DbgSymOffs, O);
|
ObjReadDbgSyms (L->F, O->Start + O->Header.DbgSymOffs, O);
|
||||||
|
|
||||||
/* Seek to the start of the line infos and read them */
|
|
||||||
ObjReadLineInfos (L->F, O->Start + O->Header.LineInfoOffs, O);
|
|
||||||
|
|
||||||
/* Read the assertions from the object file */
|
/* Read the assertions from the object file */
|
||||||
ObjReadAssertions (L->F, O->Start + O->Header.AssertOffs, O);
|
ObjReadAssertions (L->F, O->Start + O->Header.AssertOffs, O);
|
||||||
|
|
||||||
@@ -374,9 +390,6 @@ static void LibResolve (void)
|
|||||||
*/
|
*/
|
||||||
ObjReadSections (L->F, O->Start + O->Header.SegOffs, O);
|
ObjReadSections (L->F, O->Start + O->Header.SegOffs, O);
|
||||||
|
|
||||||
/* Remember from which library this module is */
|
|
||||||
O->LibName = L->Name;
|
|
||||||
|
|
||||||
/* All references to strings are now resolved, so we can delete
|
/* All references to strings are now resolved, so we can delete
|
||||||
* the module string pool.
|
* the module string pool.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user