4 readundefs(char *f, int t)
9 char *l, buf[256], *fields[64];
15 diag("could not open %s: %r", f);
18 while((l = Brdline(b, '\n')) != nil){
21 diag("%s: line too long", f);
26 n = getfields(buf, fields, nelem(fields), 1, " \t\r\n");
27 if(n == nelem(fields)){
28 diag("%s: bad format", f);
31 for(i = 0; i < n; i++){
32 s = lookup(fields[i], 0);
51 diag("value != 0 on SXREF");
53 diag("import index %d out of range", n);
54 s->value = n<<Roffset;
74 for(i = 0; i < NHASH; i++)
75 for(s = hash[i]; s != S; s = s->link)
76 if(s->sig != 0 && s->type == SXREF && (nimports == 0 || s->subtype == SIMPORT)){
78 Bprint(&bso, "IMPORT: %s sig=%lux v=%lld\n", s->name, s->sig, (vlong)s->value);
85 if(v < 0 || v >= 1<<Roffset)
86 diag("relocation offset %ld for %s out of range", v, s->name);
90 newdata(Sym *s, int o, int w, int t)
99 p->from.type = D_OREG;
103 p->to.type = D_CONST;
111 int i, j, n, off, nb, sv, ne;
112 Sym *s, *et, *str, **esyms;
114 char buf[NSNAME], *t;
117 for(i = 0; i < NHASH; i++)
118 for(s = hash[i]; s != S; s = s->link)
119 if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
121 esyms = malloc(n*sizeof(Sym*));
124 for(i = 0; i < NHASH; i++)
125 for(s = hash[i]; s != S; s = s->link)
126 if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
128 for(i = 0; i < ne-1; i++)
129 for(j = i+1; j < ne; j++)
130 if(strcmp(esyms[i]->name, esyms[j]->name) > 0){
138 et = lookup(EXPTAB, 0);
139 if(et->type != 0 && et->type != SXREF)
140 diag("%s already defined", EXPTAB);
142 str = lookup(".string", 0);
146 for(i = 0; i < ne; i++){
148 Bprint(&bso, "EXPORT: %s sig=%lux t=%d\n", s->name, s->sig, s->type);
151 p = newdata(et, off, sizeof(long), D_EXTERN);
153 p->to.offset = s->sig;
156 p = newdata(et, off, sizeof(long), D_EXTERN);
158 p->to.name = D_EXTERN;
168 p = newdata(str, sv-NSNAME, NSNAME, D_STATIC);
169 p->to.type = D_SCONST;
170 p->to.sval = malloc(NSNAME);
171 memmove(p->to.sval, buf, NSNAME);
179 p = newdata(et, off, sizeof(long), D_EXTERN);
181 p->to.name = D_STATIC;
187 p = newdata(str, sv-nb, nb, D_STATIC);
188 p->to.type = D_SCONST;
189 p->to.sval = malloc(NSNAME);
190 memmove(p->to.sval, buf, nb);
193 for(i = 0; i < 3; i++){
194 newdata(et, off, sizeof(long), D_EXTERN);