From 9cd0b7705ca56486469724e85702f8ed08c7aa51 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 9 Jan 2005 13:16:51 +0000 Subject: [PATCH] Fixed a bug: If all output data was discarded (by using file = "" in the linker config), CheckExports was never called, which in turn meant that the list of all exports was never built. This caused a crash later when the linker tried to generate a map file. The solution is to separate the creation of the exports list and the check for unresolved imports. git-svn-id: svn://svn.cc65.org/cc65/trunk@3360 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/bin.c | 2 +- src/ld65/exports.c | 20 ++++++++++++++------ src/ld65/exports.h | 11 ++++++++--- src/ld65/main.c | 5 ++++- src/ld65/o65.c | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/ld65/bin.c b/src/ld65/bin.c index 9ba09f673..680011127 100644 --- a/src/ld65/bin.c +++ b/src/ld65/bin.c @@ -262,7 +262,7 @@ void BinWriteTarget (BinDesc* D, struct File* F) * if we get an unresolved symbol. */ D->Undef = 0; /* Reset the counter */ - CheckExports (BinUnresolved, D); + CheckUnresolvedImports (BinUnresolved, D); if (D->Undef > 0) { /* We had unresolved symbols, cannot create output file */ Error ("%u unresolved external(s) found - cannot create output file", D->Undef); diff --git a/src/ld65/exports.c b/src/ld65/exports.c index 87caa5e56..0cdcb3bc0 100644 --- a/src/ld65/exports.c +++ b/src/ld65/exports.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ +/* (C) 1998-2005 Ullrich von Bassewitz */ /* Römerstraße 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -576,7 +576,7 @@ static void CheckSymType (const Export* E) Warning ("Address size mismatch for `%s': Symbol is `%s'" ", but imported from %s, %s(%lu) as `%s'", GetString (E->Name), - ExpAddrSize, + ExpAddrSize, ImpObjName, GetSourceFileName (Imp->Obj, Imp->Pos.Name), Imp->Pos.Line, @@ -669,9 +669,9 @@ static void CreateExportPool (void) -void CheckExports (ExpCheckFunc F, void* Data) -/* Check if there are any unresolved symbols. On unresolved symbols, F is - * called (see the comments on ExpCheckFunc in the data section). +void CheckExports (void) +/* Setup the list of all exports and check for export/import symbol type + * mismatches. */ { /* Create an export pool */ @@ -679,8 +679,16 @@ void CheckExports (ExpCheckFunc F, void* Data) /* Check for symbol type mismatches */ CheckSymTypes (); +} + - /* Check for unresolved externals (check here for special bin formats) */ + +void CheckUnresolvedImports (ExpCheckFunc F, void* Data) +/* Check if there are any unresolved imports. On unresolved imports, F is + * called (see the comments on ExpCheckFunc in the data section). + */ +{ + /* Check for unresolved externals */ if (ImpOpen != 0) { /* Print all open imports */ PrintUnresolved (F, Data); diff --git a/src/ld65/exports.h b/src/ld65/exports.h index bfdca3c1f..6247691d0 100644 --- a/src/ld65/exports.h +++ b/src/ld65/exports.h @@ -158,8 +158,13 @@ int IsConstExport (const Export* E); long GetExportVal (const Export* E); /* Get the value of this export */ -void CheckExports (ExpCheckFunc F, void* Data); -/* Check if there are any unresolved symbols. On unresolved symbols, F is +void CheckExports (void); +/* Setup the list of all exports and check for export/import symbol type + * mismatches. + */ + +void CheckUnresolvedImports (ExpCheckFunc F, void* Data); +/* Check if there are any unresolved imports. On unresolved imports, F is * called (see the comments on ExpCheckFunc in the data section). */ @@ -189,7 +194,7 @@ void CircularRefError (const Export* E); /* End of exports.h */ #endif - + diff --git a/src/ld65/main.c b/src/ld65/main.c index c5f4aec17..a424d37f1 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ +/* (C) 1998-2005 Ullrich von Bassewitz */ /* Römerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -512,6 +512,9 @@ int main (int argc, char* argv []) /* Check module assertions */ CheckAssertions (); + /* Check for import/export mismatches */ + CheckExports (); + /* Create the output file */ CfgWriteTarget (); diff --git a/src/ld65/o65.c b/src/ld65/o65.c index efc7856bc..c6c90b428 100644 --- a/src/ld65/o65.c +++ b/src/ld65/o65.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1999-2003 Ullrich von Bassewitz */ +/* (C) 1999-2005 Ullrich von Bassewitz */ /* Römerstraße 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -1356,7 +1356,7 @@ void O65WriteTarget (O65Desc* D, File* F) * if we get an unresolved symbol. */ D->Undef = 0; /* Reset the counter */ - CheckExports (O65Unresolved, D); + CheckUnresolvedImports (O65Unresolved, D); if (D->Undef > 0) { /* We had unresolved symbols, cannot create output file */ Error ("%u unresolved external(s) found - cannot create output file", D->Undef); -- 2.39.5