Home
       pass3.c - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
       pass3.c (1343B)
       ---
            1 #include <ctype.h>
            2 #include <stdio.h>
            3 #include <stdlib.h>
            4 
            5 #include <scc/mach.h>
            6 
            7 #include "ld.h"
            8 
            9 /* TODO: This function must go in pass2 */
           10 static void
           11 rebase(Obj *obj)
           12 {
           13         Symbol *aux;
           14         Objsym *sym;
           15 
           16         for (sym = obj->syms; sym; sym = sym->next) {
           17                 switch (sym->type) {
           18                 case 'T':
           19                 case 'D':
           20                 case 'B':
           21                         /*
           22                          * this lookup must succeed, otherwise
           23                          * we have an error in our code.
           24                          */
           25                         aux = lookup(sym->name);
           26                         aux->value += obj->secs[sym->index].base;
           27                 case 't':
           28                 case 'd':
           29                 case 'b':
           30                         sym->value += obj->secs[sym->index].base;
           31                 case 'U':
           32                 case 'N':
           33                 case '?':
           34                         break;
           35                 default:
           36                         abort();
           37                 }
           38         }
           39 }
           40 
           41 /*
           42  * rebase all the sections
           43  */
           44 void
           45 pass3(int argc, char *argv[])
           46 {
           47         int i;
           48         Obj *obj;
           49         Section *sec;
           50         Segment *seg;
           51 
           52         /*
           53          * TODO: deal with page aligment
           54          */
           55         text.base = 0x100;
           56         rodata.base = text.base + text.size;
           57         data.base = rodata.base + rodata.size;
           58         bss.base = data.base + data.size;
           59 
           60         for (obj = objhead; obj; obj = obj->next) {
           61                 for (i = 0; getsec(obj, &i, &sec); i++) {
           62                         /* TODO: deal with symbol aligment */
           63                         switch (sec->type) {
           64                         case 'T':
           65                                 seg = &text;
           66                                 break;
           67                         /* TODO: what happens with rodata? */
           68                         case 'D':
           69                                 seg = &data;
           70                                 break;
           71                         case 'B':
           72                                 seg = &bss;
           73                                 break;
           74                         default:
           75                                 abort();
           76                         }
           77 
           78                         rebase(obj, i, seg->size);
           79                         seg->size += sec.size;
           80                 }
           81         }
           82 }