ref: bcd0eb471c18a1cd0148b284b9c0a489e4ead6d5
parent: dda941923a06fad72864abc97d933957137e90d1
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 15 01:28:55 EST 2019
[libmach] Add a linked list for the segments
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -22,6 +22,7 @@
unsigned flags;
long offset;
unsigned long long size;
+ Objsect *next;
};
struct objsym {
--- a/src/cmd/size.c
+++ b/src/cmd/size.c
@@ -42,7 +42,7 @@
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 @@
}
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 @@
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;
--- 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 @@
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 @@
sp->offset = scn->s_scnptr;
sp->size = scn->s_size;
sp->type = type;
- nsecs++;
}
obj->secs = secs;
+ obj->nsecs = i;
return 1;
}