scc

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

pass2.c (779B)


      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 void
     10 mksecs(void)
     11 {
     12 	int i;
     13 	Obj *obj;
     14 	Section sec, *sp;
     15 
     16 	for (obj = objhead; obj; obj = obj->next) {
     17 		for (i = 0; getsec(obj, &i, &sec); i++) {
     18 			sp = lookupsec(sec.name);
     19 			if (sp->type == '?') {
     20 				sp->type = sec.type;
     21 				sp->flags = sec.flags;
     22 			}
     23 
     24 			if (sp->type != sec.type || sp->flags != sec.flags) {
     25 				error("incompatible definitions of section '%s'",
     26 				      sp->name);
     27 			}
     28 
     29 			sp->size = sp->size+sp->align-1 & sp->align-1;
     30 			sp->size += sec.size;
     31 		}
     32 	}
     33 }
     34 
     35 static void
     36 mksegs(void)
     37 {
     38 	merge(&text);
     39 	merge(&rodata);
     40 	merge(&data);
     41 	merge(&bss);
     42 }
     43 
     44 void
     45 pass2(int argc, char *argv[])
     46 {
     47 	unsigned long long n;
     48 	char *end;
     49 
     50 	mksecs();
     51 	mksegs();
     52 }