shithub: scc

Download patch

ref: b709b8fa6bd37944b2e0a53bef8df2fca5e9519e
parent: 65120a98fb3d4d914f79cc66dc425d7d4d81c666
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Feb 10 17:02:00 EST 2019

[ld] Several fixes

--- a/src/cmd/ld/main.c
+++ b/src/cmd/ld/main.c
@@ -199,6 +199,14 @@
 		return;
 	}
 
+	if (bintype == -1) {
+		bintype = type;
+	} else if (bintype != type) {
+		error("not compatible object file");
+		return;
+	}
+	bintype = type;
+
 	if (objread(obj, fp) < 0) {
 		error("object file corrupted");
 		goto delete;
@@ -225,7 +233,7 @@
 static void
 loadlib(FILE *fp)
 {
-	int t;
+	int t, loaded;
 	long n;
 	Objsymdef *def, *dp;
 	Symbol *sym, *p;
@@ -235,39 +243,34 @@
 		return;
 	}
 
-repeat:
 	p = &refhead;
-	if (p->next == p)
-		goto clean;
+	for (loaded = 0; p->next != p; loaded = 0) {
+		for (dp = def; dp; dp = dp->next) {
+			sym = lookup(dp->name, NOINSTALL);
+			if (!sym || !sym->def)
+				continue;
 
-	for (dp = def; dp; dp = dp->next) {
-		if ((sym = lookup(dp->name, NOINSTALL)) == NULL)
-			continue;
-		if (!sym->def)
-			break;
-	}
+			if (fseek(fp, dp->offset, SEEK_SET) == EOF) {
+				error(errstr());
+				break;
+			}
 
-	if (!dp)
-		goto clean;
+			if ((t = objtype(fp, NULL)) == -1) {
+				error("library file corrupted");
+				break;
+			}
 
-	if (fseek(fp, dp->offset, SEEK_SET) == EOF) {
-		error(errstr());
-		goto clean;
-	}
+			if (t != bintype) {
+				error("incompatible library");
+				break;
+			}
 
-	if ((t = objtype(fp, NULL)) == -1) {
-		error("library file corrupted");
-		goto clean;
+			newobject(fp, t, OUTLIB);
+			loaded = 1;
+		}
+		if (!loaded)
+			break;
 	}
-
-	if (t != bintype) {
-		error("incompatible library");
-		goto clean;
-	}
-
-	newobject(fp, t, OUTLIB);
-	goto repeat;
-
 clean:
 	free(def);
 }