From a1c19486151918ce9a7d4414a92d8eee57312550 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 4 Jan 2009 16:42:39 +0000 Subject: [PATCH] * as/link/lkrel.c, as/link/lksdcclib.c: fixed bug #2484677: Linker hangs git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5328 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 4 ++- as/link/lkrel.c | 11 ++++---- as/link/lksdcclib.c | 62 +++++++++++++++++++++++++++------------------ 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b5d86cc..c33480a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * .version, doc/sdccman.lyx: bumped sdcc version to 2.8.6 due changes in sdcc asxxxx linkers - it sholud be done 2 days ago :( * doc/README.txt: updated John Hartman's e-mail address + * as/link/lkrel.c, as/link/lksdcclib.c: + fixed bug #2484677: Linker hangs 2009-01-04 Philipp Klaus Krause @@ -322,7 +324,7 @@ 2008-11-06 Borut Razem - * src/SDCCmain.c: #fixed bug 2224960: sdcc -MM no working correctly + * src/SDCCmain.c: fixed bug #2224960: sdcc -MM no working correctly pass system include paths with -isystem to sdcpp * src/SDCCglue.c, src/pic/glue.c, src/pic16/glue.c: removed unneeded functions (closePipes), (closeTmpFiles) and (rmTmpFiles) diff --git a/as/link/lkrel.c b/as/link/lkrel.c index 02c1912c..3914aced 100644 --- a/as/link/lkrel.c +++ b/as/link/lkrel.c @@ -15,6 +15,10 @@ * */ +/* + * Extensions: P. Felber + */ + #include #include @@ -54,7 +58,7 @@ is_rel (FILE * libfp) return ret; } -/* Load a .rel file embedded in a sdcclib file */ +/* Load a standalone or embedded .rel */ int load_rel (FILE * libfp, long size) { @@ -63,10 +67,7 @@ load_rel (FILE * libfp, long size) char str[NINPUT]; long end; - if (size >= 0) - end = ftell (libfp) + size; - else - end = -1; + end = (size >= 0) ? ftell (libfp) + size : -1; while ((end < 0 || ftell (libfp) < end) && getline (str, sizeof (str), libfp) != NULL) { diff --git a/as/link/lksdcclib.c b/as/link/lksdcclib.c index 95f927d4..00d0f6bc 100644 --- a/as/link/lksdcclib.c +++ b/as/link/lksdcclib.c @@ -56,7 +56,7 @@ is_sdcclib (FILE * libfp) } /* Load a .rel file embedded in a sdcclib file */ -static void +static int LoadRel (char *libfname, FILE * libfp, char *ModName) { char str[NINPUT]; @@ -69,25 +69,21 @@ LoadRel (char *libfname, FILE * libfp, char *ModName) case 0: if (EQ (str, "")) { - getline (str, sizeof (str), libfp); - if (EQ (str, ModName)) + if (NULL != getline (str, sizeof (str), libfp) && EQ (str, ModName)) state = 1; else - { - fprintf (stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n", libfname, ModName); - lkexit (1); - } + return 0; } + else + return 0; break; + case 1: - if (EQ (str, "")) - state = 2; - break; - case 2: - load_rel (libfp, -1); - break; + return EQ (str, "") ? load_rel (libfp, -1) : 0; } } + + return 0; } #ifdef INDEXLIB @@ -114,7 +110,8 @@ buildlibraryindex_sdcclib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This state = 1; } break; - case 1: + + case 1: if (EQ (FLine, "")) { /* The next line has the name of the module and the offset @@ -149,7 +146,8 @@ buildlibraryindex_sdcclib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This return This; /* Finish, get out of here */ } break; - case 2: + + case 2: if (EQ (FLine, "")) { This->loaded = 0; @@ -193,7 +191,7 @@ LoadAdb (FILE * libfp) { char str[MAXLINE]; int state = 0; - int ToReturn = 0; + int ret = 0; while (getline (str, sizeof (str), libfp) != NULL) { @@ -203,15 +201,16 @@ LoadAdb (FILE * libfp) if (EQ (str, "")) state = 1; break; + case 1: if (EQ (str, "")) - return ToReturn; + return ret; fprintf (dfp, "%s\n", str); - ToReturn = 1; + ret = 1; break; } } - return ToReturn; + return ret; } /* Check for a symbol in a SDCC library. If found, add the embedded .rel and @@ -254,7 +253,8 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type) state = 1; } break; - case 1: + + case 1: if (EQ (FLine, "")) { /* The next line has the name of the module and the offset @@ -269,7 +269,8 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type) return 0; } break; - case 2: + + case 2: if (EQ (FLine, "")) { /* The symbol is not in this module, try the next one */ @@ -321,8 +322,12 @@ findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type) /* Jump to where the .rel begins and load it. */ fseek (libfp, lbfh->offset, SEEK_SET); - LoadRel (lbnh->libspc, libfp, ModName); - + if (!LoadRel (lbnh->libspc, libfp, ModName)) + { + fclose (libfp); + fprintf (stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n", lbfh->libspc, ModName); + lkexit (1); + } /* if cdb information required & .adb file present */ if (dflag && dfp) { @@ -349,6 +354,8 @@ static void loadfile_sdcclib (struct lbfile *lbfh) { FILE *fp; + int res; + #ifdef __CYGWIN__ char posix_path[PATH_MAX]; void cygwin_conv_to_full_posix_path (char *win_path, char *posix_path); @@ -361,13 +368,18 @@ loadfile_sdcclib (struct lbfile *lbfh) if (fp != NULL) { fseek (fp, lbfh->offset, SEEK_SET); - LoadRel (lbfh->libspc, fp, lbfh->relfil); + res = LoadRel (lbfh->libspc, fp, lbfh->relfil); fclose (fp); + + if (!res) + { + fprintf (stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n", lbfh->libspc, lbfh->relfil); + lkexit (1); + } } else { fprintf (stderr, "?ASlink-Error-Opening library '%s'\n", lbfh->libspc); - fclose (fp); lkexit (1); } } -- 2.30.2