scc

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

pass2.c (817B)


      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <limits.h>
      4 
      5 #include <scc/mach.h>
      6 
      7 #include "ld.h"
      8 
      9 static unsigned long long
     10 sectsize(int type)
     11 {
     12 	unsigned long long size;
     13 	Objlst *lp;
     14 	Objsect *sp;
     15 
     16 	size = 0;
     17 	for (lp = objhead; lp; lp = lp->next) {
     18 		for (sp = lp->obj->secs; sp; sp = sp->next) {
     19 			if (sp->type != type)
     20 				continue;
     21 			size += sp->size;
     22 		}
     23 	}
     24 
     25 	return size;
     26 }
     27 
     28 /*
     29  * calculate the size of every segment
     30  */
     31 void
     32 pass2(int argc, char *argv[])
     33 {
     34 	unsigned long long n;
     35 	char *end;
     36 	Objsect *sp;
     37 
     38 	datasiz = bsssiz = textsiz = 0;
     39 
     40 	textsiz = sectsize('T');
     41 	datasiz = sectsize('D');
     42 	bsssiz = sectsize('B');
     43 
     44 	if (Dflag) {
     45 		n = strtoull(Dflag, &end, 0);
     46 		if (n == ULLONG_MAX || *end != '\0') {
     47 			error("incorrect -D value");
     48 			exit(EXIT_FAILURE);
     49 		}
     50 		if (n > datasiz)
     51 			datasiz = n;
     52 	}
     53 }