scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit acdc0f7bf35277e027f354e14752b00c1879741d
parent c54377fd54f682b392f83d3f14a3b72b884045a2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 22 Aug 2019 19:18:27 +0100

[libmach] Remove fp field from Obj

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

Diffstat:
Minclude/scc/scc/mach.h | 3+--
Msrc/cmd/ld/pass4.c | 9+++++----
Msrc/libmach/coff32/coff32read.c | 6+++++-
Msrc/libmach/objpos.c | 2+-
Msrc/libmach/objread.c | 1-
5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -49,8 +49,7 @@ struct obj { Objsym *htab[NR_SYMHASH]; Objsym *syms; Objsect *secs; - FILE *fp; - fpos_t pos; + long pos; int nsecs; int nsyms; void *data; diff --git a/src/cmd/ld/pass4.c b/src/cmd/ld/pass4.c @@ -15,11 +15,12 @@ pass4(int argc, char *argv[]) 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(); diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c @@ -340,9 +340,13 @@ readaout(Obj *obj, FILE *fp) 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)) diff --git 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; diff --git a/src/libmach/objread.c b/src/libmach/objread.c @@ -19,7 +19,6 @@ objread(Obj *obj, FILE *fp) if ((*freadv[fmt])(obj, fp) < 0) return -1; - obj->fp = fp; return 0; }