shithub: scc

Download patch

ref: 80fae81bf042571f1d2902914302c8d552c4b95b
parent: 7665b3ee492c998789d3c9c7ad79258411f6485a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Aug 22 15:18:27 EDT 2019

[libmach] Remove fp field from Obj

This field is not needed and it encourages bad habits.
This change breaks ld which was expected.

--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -49,8 +49,7 @@
 	Objsym *htab[NR_SYMHASH];
 	Objsym *syms;
 	Objsect *secs;
-	FILE *fp;
-	fpos_t pos;
+	long pos;
 	int nsecs;
 	int nsyms;
 	void *data;
--- a/src/cmd/ld/pass4.c
+++ b/src/cmd/ld/pass4.c
@@ -15,11 +15,12 @@
 	FILE *fp;
 
 	for (lp = objhead; lp; lp = lp->next) {
-		fp = lp->obj->fp;
+		/* TODO: fp = lp->obj->fp; */
 		for (sp = lp->obj->secs; sp; sp = sp->next) {
-			if (!objpos(lp->obj, lp->obj->fp, sp->seek))
-				error("seeking for section content");
-
+			/* TODO:
+			 * if (!objpos(lp->obj, lp->obj->fp, sp->seek))
+			 *	error("seeking for section content");
+			 */
 			sec = section(sp->name);
 			if (!sec->fp) {
 				sec->fp = tmpfile();
--- a/src/libmach/coff32/coff32read.c
+++ b/src/libmach/coff32/coff32read.c
@@ -340,9 +340,13 @@
 static int
 readfile(Obj *obj, FILE *fp)
 {
+	long off;
+
 	/* TODO: Add validation of the different fields */
-	if (fgetpos(fp, &obj->pos))
+	if ((off = ftell(fp)) == EOF)
 		goto error;
+	obj->pos = off;
+
 	if (!readhdr(obj, fp))
 		goto error;
 	if (!readaout(obj, fp))
--- a/src/libmach/objpos.c
+++ b/src/libmach/objpos.c
@@ -7,7 +7,7 @@
 int
 objpos(Obj *obj, FILE *fp, long pos)
 {
-	if (fsetpos(fp, &obj->pos))
+	if (fseek(fp, obj->pos, SEEK_SET) == EOF)
 		return 0;
 	if (fseek(fp, pos, SEEK_CUR) < 0)
 		return 0;
--- a/src/libmach/objread.c
+++ b/src/libmach/objread.c
@@ -19,7 +19,6 @@
 
 	if ((*freadv[fmt])(obj, fp) < 0)
 		return -1;
-	obj->fp = fp;
 
 	return 0;
 }