* as/link/lkrel.c, as/link/lksdcclib.c:
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 4 Jan 2009 16:42:39 +0000 (16:42 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 4 Jan 2009 16:42:39 +0000 (16:42 +0000)
  fixed bug #2484677: Linker hangs

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5328 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
as/link/lkrel.c
as/link/lksdcclib.c

index 3b5d86cc01d13c3fde3d4ecfe780da39651a1b8d..c33480a8d7869483f35af68d0eba23aef6238031 100644 (file)
--- 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 <pkk AT spth.de>
 
 
 2008-11-06 Borut Razem <borut.razem AT siol.net>
 
-       * 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)
index 02c1912c8ccd185d03c3377c3c74dd15d2f53cb5..3914acedc96b80931c6dc2f5e1f7e90b1c6ffafb 100644 (file)
  *
  */
 
+/*
+ * Extensions: P. Felber
+ */
+
 #include <string.h>
 #include <assert.h>
 
@@ -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)
        {
index 95f927d4063b23a7e723d12e85ccf590527c6721..00d0f6bce0602c73c1bf6b93058a5eba4bcb2332 100644 (file)
@@ -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, "<FILE>"))
            {
-             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, "<REL>"))
-           state = 2;
-         break;
-       case 2:
-         load_rel (libfp, -1);
-         break;
+          return EQ (str, "<REL>") ? 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, "<MODULE>"))
            {
              /* 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, "</MODULE>"))
            {
              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, "<ADB>"))
            state = 1;
          break;
+
        case 1:
          if (EQ (str, "</ADB>"))
-           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, "<MODULE>"))
            {
              /* 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, "</MODULE>"))
            {
              /* 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);
     }
 }