From: uz Date: Fri, 28 Jan 2011 16:03:55 +0000 (+0000) Subject: Adapted to new library format. X-Git-Tag: V2.13.3~514 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8af53cf22a6549fb1b6ad4250646b6c10df21c5b;p=cc65 Adapted to new library format. git-svn-id: svn://svn.cc65.org/cc65/trunk@4946 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/fileio.c b/src/ld65/fileio.c index 4913e3ca6..af00e3567 100644 --- a/src/ld65/fileio.c +++ b/src/ld65/fileio.c @@ -198,7 +198,8 @@ unsigned Read8 (FILE* F) { int C = getc (F); if (C == EOF) { - Error ("Read error (file corrupt?)"); + long Pos = ftell (F); + Error ("Read error at position %ld (file corrupt?)", Pos); } return C; } @@ -325,7 +326,8 @@ void* ReadData (FILE* F, void* Data, unsigned Size) /* Explicitly allow reading zero bytes */ if (Size > 0) { 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; diff --git a/src/ld65/library.c b/src/ld65/library.c index e94fbfb50..9047f3e83 100644 --- a/src/ld65/library.c +++ b/src/ld65/library.c @@ -197,6 +197,9 @@ static ObjData* ReadIndexEntry (Library* L) /* Create a new entry and insert it into the list */ ObjData* O = NewObjData (); + /* Remember from which library this module is */ + O->LibName = L->Name; + /* Module name */ O->Name = ReadStr (L->F); @@ -206,19 +209,35 @@ static ObjData* ReadIndexEntry (Library* L) O->Start = Read32 (L->F); Read32 (L->F); /* Skip Size */ + /* Done */ + 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, FileGetPos (L->F), O); + ObjReadStrPool (L->F, O->Start + O->Header.StrPoolOffs, O); - /* Skip the import size, then read the imports */ - (void) ReadVar (L->F); - ObjReadImports (L->F, FileGetPos (L->F), O); + /* Read the files list */ + ObjReadFiles (L->F, O->Start + O->Header.FileOffs, O); - /* Skip the export size, then read the exports */ - (void) ReadVar (L->F); - ObjReadExports (L->F, FileGetPos (L->F), O); + /* Read the line infos */ + ObjReadLineInfos (L->F, O->Start + O->Header.LineInfoOffs, O); - /* Done */ - return 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); } @@ -226,7 +245,7 @@ static ObjData* ReadIndexEntry (Library* L) static void LibReadIndex (Library* L) /* Read the index of a library file */ { - unsigned ModuleCount; + unsigned ModuleCount, I; /* Seek to the start of the index */ LibSeek (L, L->Header.IndexOffs); @@ -239,6 +258,13 @@ static void LibReadIndex (Library* L) while (ModuleCount--) { 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? */ 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 */ 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 */ 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); - /* Remember from which library this module is */ - O->LibName = L->Name; - /* All references to strings are now resolved, so we can delete * the module string pool. */