shithub: scc

Download patch

ref: 718fad000a4821aeab5d6050e8a93298a1a67e77
parent: e27e71e4129cb93d1af220f69a621fea7402af43
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Aug 21 12:03:36 EDT 2019

[ld] Fix seeking into the object file

Object files can be inside of a library, and for this reason
is not a good idea to use fseek directly because it can result
in wrong locations.

--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -70,6 +70,7 @@
 extern int objwrite(Obj *obj, FILE *fp);
 extern int objsect(Obj *obj);
 extern int objsyms(Obj *obj);
+extern int objpos(Obj *obj, FILE *fp, long pos);
 extern int archive(FILE *fp);
 extern long armember(FILE *fp, char *member);
 extern long setindex(int type, long nsyms, Objsymdef *def, FILE *fp);
--- a/src/cmd/ld/pass4.c
+++ b/src/cmd/ld/pass4.c
@@ -17,7 +17,8 @@
 	for (lp = objhead; lp; lp = lp->next) {
 		fp = lp->obj->fp;
 		for (sp = lp->obj->secs; sp; sp = sp->next) {
-			fseek(fp, sp->seek, SEEK_SET);
+			if (!objpos(lp->obj, lp->obj->fp, sp->seek))
+				error("seeking for section content");
 
 			sec = section(sp->name);
 			if (!sec->fp) {
--- a/src/libmach/libmach.h
+++ b/src/libmach/libmach.h
@@ -31,7 +31,6 @@
 /* common functions */
 extern int pack(int order, unsigned char *dst, char *fmt, ...);
 extern int unpack(int order, unsigned char *src, char *fmt, ...);
-extern int objpos(Obj *obj, FILE *fp, long pos);
 extern int objfree(Obj *obj, int what);
 
 /* coff32 functions */