simple c99 compiler
git clone git://
Log | Files | Refs | README | LICENSE

commit ab1d0cf5a9ed003d4337a3bac11116e7fb1fde8b
parent de94ca2cddfae5beede22d0533c17ec32ff3653b
Author: Roberto E. Vargas Caballero <>
Date:   Wed, 21 Aug 2019 16:03:36 +0100

[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.

Minclude/scc/scc/mach.h | 1+
Msrc/cmd/ld/pass4.c | 3++-
Msrc/libmach/libmach.h | 1-
3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -70,6 +70,7 @@ extern int objstrip(Obj *obj); 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); diff --git a/src/cmd/ld/pass4.c b/src/cmd/ld/pass4.c @@ -17,7 +17,8 @@ pass4(int argc, char *argv[]) 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) { diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -31,7 +31,6 @@ enum deltype { /* 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 */