1
0
mirror of https://github.com/cc65/cc65.git synced 2025-04-08 19:38:55 +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:
uz 2011-01-28 16:03:55 +00:00
parent fa1b5f5f3c
commit 8af53cf22a
2 changed files with 42 additions and 27 deletions

View File

@ -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;

View File

@ -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,27 +209,43 @@ static ObjData* ReadIndexEntry (Library* L)
O->Start = Read32 (L->F);
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 */
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)
/* 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.
*/