scc

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

commit 74082f4925966f86b2d20c7f95246a239119c0d8
parent 2c2ed02aeb49b2c87ee4271047110ee682bccc47
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 15 Feb 2019 06:28:55 +0000

[libmach] Add a linked list for the segments

Diffstat:
Minclude/scc/scc/mach.h | 1+
Msrc/cmd/size.c | 11+++++------
Msrc/libmach/coff32/coff32getsect.c | 10+++++-----
3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -22,6 +22,7 @@ struct objsect { unsigned flags; long offset; unsigned long long size; + Objsect *next; }; struct objsym { diff --git a/src/cmd/size.c b/src/cmd/size.c @@ -42,7 +42,7 @@ newobject(FILE *fp, int type) int i; Obj *obj; unsigned long long total, *p; - Objsect *secp; + Objsect *sp; struct sizes siz; if ((obj = objnew(type)) == NULL) { @@ -56,9 +56,8 @@ newobject(FILE *fp, int type) } siz.text = siz.data = siz.bss = 0; - for (i = 0; i < obj->nsyms; i++) { - secp = &obj->secs[i]; - switch (secp->type) { + for (sp = obj->secs; sp; sp = sp->next) { + switch (sp->type) { case 'T': p = &siz.text; break; @@ -72,12 +71,12 @@ newobject(FILE *fp, int type) continue; } - if (*p > ULLONG_MAX - secp->size) { + if (*p > ULLONG_MAX - sp->size) { error("integer overflow"); goto err; } - *p += secp->size; + *p += sp->size; } total = siz.text + siz.data + siz.bss; diff --git a/src/libmach/coff32/coff32getsect.c b/src/libmach/coff32/coff32getsect.c @@ -9,7 +9,7 @@ int coff32getsect(Obj *obj) { - int nsecs; + int i; unsigned sflags, type; unsigned long flags; FILHDR *hdr; @@ -21,13 +21,13 @@ coff32getsect(Obj *obj) hdr = &coff->hdr; scn = coff->scns; - nsecs = 0; secs = malloc(sizeof(Objsect) * hdr->f_nscns); if (!secs) return -1; - for (sp = secs; sp < &secs[hdr->f_nscns]; sp++) { - flags = scn->s_flags; + for (i = 0; i < hdr->f_nscns; i++) { + sp = &secs[i]; + sp->next = (i < hdr->f_nscns-1) ? &secs[i+1] : NULL; if (flags & STYP_TEXT) { type = 'T'; @@ -66,9 +66,9 @@ coff32getsect(Obj *obj) sp->offset = scn->s_scnptr; sp->size = scn->s_size; sp->type = type; - nsecs++; } obj->secs = secs; + obj->nsecs = i; return 1; }