date and time created 83/07/01 09:21:43 by dlw
[unix-history] / usr / src / old / as.vax / assyms.c
CommitLineData
f70ab843
RH
1/*
2 * Copyright (c) 1982 Regents of the University of California
3 */
4#ifndef lint
28219de3 5static char sccsid[] = "@(#)assyms.c 4.12 %G%";
f70ab843
RH
6#endif not lint
7
5178805d
BJ
8#include <stdio.h>
9#include <ctype.h>
5178805d
BJ
10#include "as.h"
11#include "asscan.h"
12#include "assyms.h"
13
14/*
15 * Managers for chunks of symbols allocated from calloc()
16 * We maintain a linked list of such chunks.
17 *
18 */
19struct allocbox *allochead; /*head of chunk list*/
20struct allocbox *alloctail; /*tail*/
21struct allocbox *newbox; /*for creating a new chunk*/
22struct symtab *nextsym; /*next symbol free*/
23int symsleft; /*slots left in current chunk*/
24
25struct symtab **symptrs;
26struct symtab **symdelim[NLOC + NLOC +1];
27struct symtab **symptrub;
28/*
29 * Managers for the dynamically extendable hash table
30 */
31struct hashdallop *htab;
32
f70ab843 33Iptr *itab[NINST]; /*maps opcodes to instructions*/
5178805d
BJ
34/*
35 * Counts what went into the symbol table, so that the
36 * size of the symbol table can be computed.
37 */
38int nsyms; /* total number in the symbol table */
39int njxxx; /* number of jxxx entrys */
40int nforgotten; /* number of symbols erroneously entered */
41int nlabels; /* number of label entries */
5178805d
BJ
42
43/*
44 * Managers of the symbol literal storage.
5178805d 45 */
5178805d 46struct strpool *strplhead = 0;
5178805d
BJ
47
48symtabinit()
49{
50 allochead = 0;
51 alloctail = 0;
52 nextsym = 0;
53 symsleft = 0;
5178805d 54 strpoolalloc(); /* get the first strpool storage area */
5178805d
BJ
55 htab = 0;
56 htaballoc(); /* get the first part of the hash table */
57}
58
59/*
60 * Install all known instructions in the symbol table
61 */
62syminstall()
63{
f70ab843 64 register Iptr ip;
5178805d
BJ
65 register struct symtab **hp;
66 register char *p1, *p2;
f70ab843
RH
67 register int i;
68
69 for (i = 0; i < NINST; i++)
70 itab[i] = (Iptr*)BADPOINT;
5178805d 71
ec43bca4
RH
72 for (ip = (Iptr)instab; FETCHNAME(ip)[0]; ip++) {
73 p1 = FETCHNAME(ip);
5178805d
BJ
74 p2 = yytext;
75 while (*p2++ = *p1++);
76 hp = lookup(0); /* 0 => don't install this*/
77 if (*hp==NULL) {
78 *hp = (struct symtab *)ip;
451260e7
RH
79 if ( (ip->s_tag!=INSTn)
80 && (ip->s_tag!=INST0)
81 && (ip->s_tag!=0))
5178805d 82 continue; /* was pseudo-op */
f70ab843
RH
83 if (itab[ip->i_eopcode] == (Iptr*)BADPOINT){
84 itab[ip->i_eopcode] =
85 (Iptr*)ClearCalloc(256, sizeof(Iptr));
86 for (i = 0; i < 256; i++)
87 itab[ip->i_eopcode][i] =
88 (Iptr)BADPOINT;
89 }
90 itab[ip->i_eopcode][ip->i_popcode] = ip;
5178805d
BJ
91 }
92 }
93} /*end of syminstall*/
94
95
96/*
97 * Assign final values to symbols,
98 * and overwrite the index field with its relative position in
99 * the symbol table we give to the loader.
100 */
101extern struct exec hdr;
102
103freezesymtab()
104{
105 register struct symtab *sp;
106 long bs;
107 register int relpos = 0;
108 register struct symtab *ubsp;
109 register struct allocbox *allocwalk;
110
111 DECLITERATE(allocwalk, sp, ubsp)
112 {
451260e7 113 if (sp->s_tag >= IGNOREBOUND)
5178805d
BJ
114 continue; /*totally ignore jxxx entries */
115 /*
116 * Ignore stabs, but give them a symbol table index
117 */
451260e7 118 if (sp->s_type & STABFLAG)
5178805d 119 goto assignindex;
451260e7
RH
120 if ((sp->s_type&XTYPE)==XUNDEF)
121 sp->s_type = XXTRN+XUNDEF;
122 else if ((sp->s_type&XTYPE)==XDATA)
123 sp->s_value += usedot[sp->s_index].e_xvalue;
124 else if ((sp->s_type&XTYPE)==XTEXT)
125 sp->s_value += usedot[sp->s_index].e_xvalue;
126 else if ((sp->s_type&XTYPE)==XBSS) {
127 bs = sp->s_value;
128 sp->s_value = hdr.a_bss + datbase;
5178805d
BJ
129 hdr.a_bss += bs;
130 }
131 assignindex:
ec43bca4 132 if ( (FETCHNAME(sp)[0] != 'L')
451260e7 133 || (sp->s_tag != LABELID)
5178805d
BJ
134 || savelabels
135 ) /*then, we will write it later on*/
451260e7 136 sp->s_index = relpos++;
5178805d
BJ
137 }
138}
139
140
141
142/*
143 * For all of the stabs that had their final value undefined during pass 1
144 * and during pass 2 assign a final value.
145 * We have already given stab entrys a initial approximation
146 * when we constsructed the sorted symbol table.
147 * Iteration order doesn't matter.
148 */
ac73cea0
AF
149
150stabfix()
151{
5178805d
BJ
152 register struct symtab *sp, **cosp;
153 register struct symtab *p;
154
155 SYMITERATE(cosp, sp){
451260e7
RH
156 if(sp->s_ptype && (sp->s_type & STABFLAG)) {
157 p = sp->s_dest;
ac73cea0
AF
158/*
159 * STABFLOATING indicates that the offset has been saved in s_desc, s_other
160 */
161 if(sp->s_tag == STABFLOATING) {
162 sp->s_value = ( ( ((unsigned char) sp->s_other) << 16) | ( (unsigned short) sp->s_desc ) );
163 sp->s_value = sp->s_value + p->s_value;
164 }
165 else sp->s_value = p->s_value;
451260e7
RH
166 sp->s_index = p->s_index;
167 sp->s_type = p->s_type;
ac73cea0
AF
168
169
5178805d
BJ
170 }
171 }
172}
173
174char *Calloc(number, size)
175 int number, size;
176{
177 register char *newstuff;
f70ab843
RH
178 char *sbrk();
179 newstuff = sbrk(number*size);
5178805d
BJ
180 if ((int)newstuff == -1){
181 yyerror("Ran out of Memory");
182 delexit();
183 }
184 return(newstuff);
185}
186
187char *ClearCalloc(number, size)
188 int number, size;
189{
190 register char *newstuff; /* r11 */
191 register int length = number * size; /* r10 */
f70ab843
RH
192#ifdef lint
193 length = length;
194#endif length
5178805d
BJ
195 newstuff = Calloc(number, size);
196 asm("movc5 $0, (r0), $0, r10, (r11)");
197 return(newstuff);
198}
199
200struct symtab *symalloc()
201{
202 if (symsleft == 0){
203 newbox = (struct allocbox *)ClearCalloc(1,ALLOCQTY);
204 symsleft = SYMDALLOP;
205 nextsym = &newbox->symslots[0];
5178805d
BJ
206 if (alloctail == 0){
207 allochead = alloctail = newbox;
208 } else {
209 alloctail->nextalloc = newbox;
210 alloctail = newbox;
211 }
212 }
213 --symsleft;
214 ++nsyms;
5178805d
BJ
215 return(nextsym++);
216}
217
5178805d
BJ
218strpoolalloc()
219{
220 register struct strpool *new;
221
222 new = (struct strpool *)Calloc(1, sizeof (struct strpool));
223 new->str_nalloc = 0;
224 new->str_next = strplhead;
225 strplhead = new;
226}
5178805d
BJ
227
228symcmp(Pptr, Qptr)
229 struct symtab **Pptr, **Qptr;
230{
231 register struct symtab *p = *Pptr;
232 register struct symtab *q = *Qptr;
451260e7 233 if (p->s_index < q->s_index)
5178805d 234 return(-1);
451260e7 235 if (p->s_index > q->s_index)
5178805d 236 return(1);
451260e7 237 if (p->s_value < q->s_value)
5178805d 238 return(-1);
451260e7 239 if (p->s_value > q->s_value)
5178805d
BJ
240 return(1);
241 /*
242 * Force jxxx entries to virtually preceed labels defined
243 * to follow the jxxxx instruction, so that bumping the
244 * jxxx instruction correctly fixes up the following labels
245 */
451260e7 246 if (p->s_tag >= IGNOREBOUND) /*p points to a jxxx*/
5178805d 247 return(-1);
451260e7 248 if (q->s_tag >= IGNOREBOUND)
5178805d
BJ
249 return(1);
250 /*
251 * both are now just plain labels; the relative order doesn't
252 * matter. Both can't be jxxxes, as they would have different
253 * values.
254 */
255 return(0);
256} /*end of symcmp*/
257
258/*
259 * We construct the auxiliary table of pointers, symptrs and
260 * symdelim
261 * We also assign preliminary values to stab entries that did not yet
262 * have an absolute value (because they initially referred to
263 * forward references). We don't worry about .stabds, as they
264 * already have an estimated final value
265 */
266
267sortsymtab()
268{
269 register struct symtab *sp;
270 register struct symtab **cowalk;
271 register struct allocbox *allocwalk;
272 struct symtab *ubsp;
273 int segno;
274 int slotno;
275 int symsin; /*number put into symptrs*/
276
277 symptrs = (struct symtab **)Calloc(nsyms + 2, sizeof *symptrs);
278 /*
279 * Allocate one word at the beginning of the symptr array
280 * so that backwards scans through the symptr array will
281 * work correctly while scanning through the zeroth segment
282 */
283 *symptrs++ = 0;
284 cowalk = symptrs;
285 symsin = 0;
286 DECLITERATE(allocwalk, sp, ubsp) {
451260e7
RH
287 if (sp->s_ptype && (sp->s_type &STABFLAG)){
288 sp->s_value = sp->s_dest->s_value;
289 sp->s_index = sp->s_dest->s_index;
5178805d
BJ
290 }
291 if (symsin >= nsyms)
292 yyerror("INTERNAL ERROR: overfilled symbol table indirection table");
293 *cowalk++ = sp;
294 symsin++;
295 }
296 if (symsin != nsyms)
297 yyerror("INTERNAL ERROR: installed %d syms, should have installed %d",
298 symsin, nsyms);
299 symptrub = &symptrs[nsyms ];
300 qsort(symptrs, nsyms, sizeof *symptrs, symcmp);
301 symdelim[0] = symptrs;
302 for (cowalk = symptrs, sp = *cowalk, segno = 0, slotno = 1;
303 segno < NLOC + NLOC;
304 segno++, slotno++){
451260e7 305 for (; sp && sp->s_index == segno; sp = *++cowalk);
5178805d
BJ
306 symdelim[slotno] = cowalk; /*forms the ub delimeter*/
307 }
308} /*end of sortsymtab*/
309
310#ifdef DEBUG
311dumpsymtab()
312{
313 register int segno;
314 register struct symtab *sp, **cosp, *ub;
315 char *tagstring();
316
317 printf("Symbol Table dump:\n");
318 for (segno = 0; segno < NLOC + NLOC; segno++){
319 printf("Segment number: %d\n", segno);
320 SEGITERATE(segno, 0, 0, cosp, sp, ub, ++){
5178805d 321 printf("\tSeg: %d \"%s\" value: %d index: %d tag %s\n",
ec43bca4 322 segno, FETCHNAME(sp),
451260e7
RH
323 sp->s_value, sp->s_index,
324 tagstring(sp->s_tag));
5178805d 325 printf("\t\ttype: %d jxbump %d jxfear: %d\n",
451260e7 326 sp->s_type, sp->s_jxbump, sp->s_jxfear);
5178805d
BJ
327 }
328 printf("\n\n");
329 }
330}
331
332static char tagbuff[4];
333
334char *tagstring(tag)
335 unsigned char tag;
336{
337 switch(tag){
338 case JXACTIVE: return("active");
339 case JXNOTYET: return("notyet");
340 case JXALIGN: return("align");
341 case JXQUESTIONABLE: return("jxquestionable");
342 case JXINACTIVE: return("inactive");
343 case JXTUNNEL: return("tunnel");
344 case OBSOLETE: return("obsolete");
345 case IGNOREBOUND: return("ignorebound");
346 case STABFLOATING: return("stabfloating");
347 case STABFIXED: return("stabfixed");
348 case LABELID: return("labelid");
349 case OKTOBUMP: return("oktobump");
350 case ISET: return("iset");
351 case ILSYM: return("ilsym");
352 default: sprintf(tagbuff,"%d", tag);
353 return(tagbuff);
354 }
355}
356#endif DEBUG
357
358htaballoc()
359{
360 register struct hashdallop *new;
361 new = (struct hashdallop *)ClearCalloc(1, sizeof (struct hashdallop));
362 if (htab == 0)
363 htab = new;
364 else { /* add AFTER the 1st slot */
365 new->h_next = htab->h_next;
366 htab->h_next = new;
367 }
368}
369
370#define HASHCLOGGED (NHASH / 2)
371
372/*
373 * Lookup a symbol stored in extern yytext.
374 * All strings passed in via extern yytext had better have
375 * a trailing null. Strings are placed in yytext for hashing by
376 * syminstall() and by yylex();
377 *
378 * We take pains to avoid function calls; this functdion
379 * is called quite frequently, and the calls overhead
380 * in the vax contributes significantly to the overall
381 * execution speed of as.
382 */
383struct symtab **lookup(instflg)
384 int instflg; /* 0: don't install */
385{
386 static int initialprobe;
387 register struct symtab **hp;
388 register char *from;
389 register char *to;
390 register int len;
391 register int nprobes;
ec43bca4
RH
392 static struct hashdallop *hdallop;
393 static struct symtab **emptyslot;
394 static struct hashdallop *emptyhd;
395 static struct symtab **hp_ub;
396 static struct strdesc strdp;
5178805d
BJ
397
398 emptyslot = 0;
399 for (nprobes = 0, from = yytext;
400 *from;
401 nprobes <<= 2, nprobes += *from++)
402 continue;
403 nprobes += from[-1] << 5;
404 nprobes %= NHASH;
405 if (nprobes < 0)
406 nprobes += NHASH;
407
408 initialprobe = nprobes;
409 for (hdallop = htab; hdallop != 0; hdallop = hdallop->h_next){
410 for (hp = &(hdallop->h_htab[initialprobe]),
411 nprobes = 1,
412 hp_ub = &(hdallop->h_htab[NHASH]);
413 (*hp) && (nprobes < NHASH);
414 hp += nprobes,
415 hp -= (hp >= hp_ub) ? NHASH:0,
416 nprobes += 2)
417 {
418 from = yytext;
ec43bca4 419 to = FETCHNAME(*hp);
5178805d
BJ
420 while (*from && *to)
421 if (*from++ != *to++)
422 goto nextprobe;
423 if (*to == *from) /*assert both are == 0*/
424 return(hp);
28219de3 425 nextprobe: ;
5178805d
BJ
426 }
427 if (*hp == 0 && emptyslot == 0 &&
428 hdallop->h_nused < HASHCLOGGED) {
429 emptyslot = hp;
430 emptyhd = hdallop;
431 }
432 }
433 if (emptyslot == 0) {
434 htaballoc();
435 hdallop = htab->h_next; /* aren't we smart! */
436 hp = &hdallop->h_htab[initialprobe];
437 } else {
438 hdallop = emptyhd;
439 hp = emptyslot;
440 }
441 if (instflg) {
442 *hp = symalloc();
443 hdallop->h_nused++;
ad67d5e5 444 for (from = yytext, len = 0; *from++; len++)
5178805d 445 continue;
ad67d5e5 446 /*
ec43bca4
RH
447 * save string and trailing null, both
448 * internally, and in the string temporary file
ad67d5e5 449 */
ec43bca4
RH
450 strdp.sd_stroff = strfilepos;
451 strdp.sd_place = STR_BOTH;
452 strdp.sd_strlen = len + 1; /* length and null */
453 fputs(yytext, strfile); /* string */
454 putc(0, strfile); /* null */
455 strfilepos += strdp.sd_strlen;
456 (*hp)->s_name = (char *)savestr(yytext, &strdp);
5178805d
BJ
457 }
458 return(hp);
459} /*end of lookup*/
ad67d5e5 460/*
ec43bca4 461 * save a string str, descriptor strdp, in the string pool
ad67d5e5 462 */
ec43bca4 463struct strdesc *savestr(str, strdp)
ad67d5e5 464 char *str;
ec43bca4 465 struct strdesc *strdp;
5178805d 466{
ec43bca4
RH
467 reg struct strdesc *res;
468 int tlen;
469
470 tlen = sizeof(struct strdesc) - sizeof(res->sd_string);
471 if (strdp->sd_place & STR_FILE)
472 tlen += strdp->sd_strlen;
5178805d 473
ec43bca4 474 if (tlen >= (STRPOOLDALLOP - strplhead->str_nalloc))
5178805d 475 strpoolalloc();
ec43bca4
RH
476 res = (struct strdesc *)(strplhead->str_names + strplhead->str_nalloc);
477 res[0] = *strdp;
478 if (strdp->sd_place & STR_FILE)
479 movestr(res[0].sd_string, str, strdp->sd_strlen);
480 strplhead->str_nalloc += tlen;
ad67d5e5 481 return(res);
5178805d
BJ
482}
483
5178805d
BJ
484/*
485 * The relocation information is saved internally in an array of
486 * lists of relocation buffers. The relocation buffers are
487 * exactly the same size as a token buffer; if we use VM for the
488 * temporary file we reclaim this storage, otherwise we create
489 * them by mallocing.
490 */
491#define RELBUFLG TOKBUFLG
492#define NRELOC ((TOKBUFLG - \
493 (sizeof (int) + sizeof (struct relbufdesc *)) \
494 ) / (sizeof (struct relocation_info)))
495
496struct relbufdesc{
497 int rel_count;
498 struct relbufdesc *rel_next;
499 struct relocation_info rel_reloc[NRELOC];
500};
501extern struct relbufdesc *tok_free;
502#define rel_free tok_free
503static struct relbufdesc *rel_temp;
451260e7
RH
504struct relocation_info r_can_1PC;
505struct relocation_info r_can_0PC;
5178805d
BJ
506
507initoutrel()
508{
451260e7
RH
509 r_can_0PC.r_address = 0;
510 r_can_0PC.r_symbolnum = 0;
511 r_can_0PC.r_pcrel = 0;
512 r_can_0PC.r_length = 0;
513 r_can_0PC.r_extern = 0;
514
515 r_can_1PC = r_can_0PC;
5178805d
BJ
516 r_can_1PC.r_pcrel = 1;
517}
518
5b3c350a
RH
519outrel(xp, reloc_how)
520 register struct exp *xp;
f70ab843 521 int reloc_how; /* TYPB..TYPH + (possibly)RELOC_PCREL */
5178805d 522{
5b3c350a
RH
523 struct relocation_info reloc;
524 register int x_type_mask;
ad67d5e5 525 int pcrel;
5178805d 526
5b3c350a
RH
527 x_type_mask = xp->e_xtype & ~XFORW;
528 pcrel = reloc_how & RELOC_PCREL;
529 reloc_how &= ~RELOC_PCREL;
530
5178805d
BJ
531 if (bitoff&07)
532 yyerror("Padding error");
5b3c350a 533 if (x_type_mask == XUNDEF)
5178805d
BJ
534 yyerror("Undefined reference");
535
5b3c350a
RH
536 if ( (x_type_mask != XABS) || pcrel ) {
537 if (ty_NORELOC[reloc_how])
f70ab843 538 yyerror("Illegal Relocation of floating or large int number.");
5b3c350a 539 reloc = pcrel ? r_can_1PC : r_can_0PC;
451260e7 540 reloc.r_address = dotp->e_xvalue -
030352e9 541 ( (dotp < &usedot[NLOC] || readonlydata) ? 0 : datbase );
5b3c350a
RH
542 reloc.r_length = ty_nlg[reloc_how];
543 switch(x_type_mask){
5178805d 544 case XXTRN | XUNDEF:
5b3c350a 545 reloc.r_symbolnum = xp->e_xname->s_index;
5178805d
BJ
546 reloc.r_extern = 1;
547 break;
548 default:
5b3c350a
RH
549 if (readonlydata && (x_type_mask&~XXTRN) == XDATA)
550 x_type_mask = XTEXT | (x_type_mask&XXTRN);
551 reloc.r_symbolnum = x_type_mask;
5178805d
BJ
552 break;
553 }
554 if ( (relfil == 0) || (relfil->rel_count >= NRELOC) ){
555 if (rel_free){
556 rel_temp = rel_free;
557 rel_free = rel_temp->rel_next;
558 } else {
559 rel_temp = (struct relbufdesc *)
560 Calloc(1,sizeof (struct relbufdesc));
561 }
562 rel_temp->rel_count = 0;
563 rel_temp->rel_next = relfil;
564 relfil = rusefile[dotp - &usedot[0]] = rel_temp;
565 }
566 relfil->rel_reloc[relfil->rel_count++] = reloc;
567 }
568 /*
569 * write the unrelocated value to the text file
570 */
5b3c350a
RH
571 dotp->e_xvalue += ty_nbyte[reloc_how];
572 if (pcrel)
573 xp->e_xvalue -= dotp->e_xvalue;
f70ab843
RH
574 switch(reloc_how){
575 case TYPO:
576 case TYPQ:
577
578 case TYPF:
579 case TYPD:
580 case TYPG:
581 case TYPH:
582 bignumwrite(xp->e_number, reloc_how);
583 break;
584
585 default:
586 bwrite((char *)&(xp->e_xvalue), ty_nbyte[reloc_how], txtfil);
587 break;
588 }
5178805d
BJ
589}
590/*
591 * Flush out all of the relocation information.
592 * Note that the individual lists of buffers are in
593 * reverse order, so we must reverse them
594 */
595off_t closeoutrel(relocfile)
596 BFILE *relocfile;
597{
598 int locindex;
599 u_long Closeoutrel();
600
601 trsize = 0;
602 for (locindex = 0; locindex < NLOC; locindex++){
603 trsize += Closeoutrel(rusefile[locindex], relocfile);
604 }
605 drsize = 0;
606 for (locindex = 0; locindex < NLOC; locindex++){
607 drsize += Closeoutrel(rusefile[NLOC + locindex], relocfile);
608 }
609 return(trsize + drsize);
610}
611
612u_long Closeoutrel(relfil, relocfile)
613 struct relbufdesc *relfil;
614 BFILE *relocfile;
615{
616 u_long tail;
617 if (relfil == 0)
618 return(0L);
619 tail = Closeoutrel(relfil->rel_next, relocfile);
620 bwrite((char *)&relfil->rel_reloc[0],
621 relfil->rel_count * sizeof (struct relocation_info),
622 relocfile);
623 return(tail + relfil->rel_count * sizeof (struct relocation_info));
624}
625
451260e7 626#define NOUTSYMS (nsyms - njxxx - nforgotten - (savelabels ? 0 : nlabels))
5178805d
BJ
627int sizesymtab()
628{
451260e7 629 return (sizeof (struct nlist) * NOUTSYMS);
5178805d 630}
5178805d
BJ
631/*
632 * Write out n symbols to file f, beginning at p
633 * ignoring symbols that are obsolete, jxxx instructions, and
634 * possibly, labels
635 */
5178805d
BJ
636int symwrite(symfile)
637 BFILE *symfile;
638{
ec43bca4
RH
639 int symsout; /*those actually written*/
640 int symsdesired = NOUTSYMS;
641 reg struct symtab *sp, *ub;
ec43bca4
RH
642 char *name; /* temp to save the name */
643 int nread;
644 char rbuf[2048];
645 int i;
451260e7
RH
646 /*
647 * We use sp->s_index to hold the length of the
648 * name; it isn't used for anything else
649 */
5178805d
BJ
650 register struct allocbox *allocwalk;
651
652 symsout = 0;
653 DECLITERATE(allocwalk, sp, ub)
654 {
451260e7 655 if (sp->s_tag >= IGNOREBOUND)
5178805d 656 continue;
ec43bca4 657 if ((FETCHNAME(sp)[0] == 'L') && (sp->s_tag == LABELID) && !savelabels)
5178805d
BJ
658 continue;
659 symsout++;
451260e7 660
451260e7 661 name = sp->s_name; /* save pointer */
ad67d5e5
RH
662 /*
663 * the length of the symbol table string
664 * always includes the trailing null
665 */
ec43bca4
RH
666 if (sp->s_name && (sp->s_index = STRLEN(sp))){
667 sp->s_nmx = STROFF(sp); /* clobber */
451260e7 668 } else {
ad67d5e5 669 sp->s_nmx = 0;
451260e7 670 }
451260e7 671 sp->s_type = (sp->s_ptype != 0) ? sp->s_ptype : (sp->s_type & (~XFORW));
030352e9
BJ
672 if (readonlydata && (sp->s_type&~N_EXT) == N_DATA)
673 sp->s_type = N_TEXT | (sp->s_type & N_EXT);
f70ab843 674 bwrite((char *)&sp->s_nm, sizeof (struct nlist), symfile);
451260e7 675 sp->s_name = name; /* restore pointer */
5178805d
BJ
676 }
677 if (symsout != symsdesired)
678 yyerror("INTERNAL ERROR: Wrote %d symbols, wanted to write %d symbols\n",
679 symsout, symsdesired);
5178805d 680 /*
ec43bca4
RH
681 * Copy the string temporary file to the symbol file,
682 * copying all the strings and symbols we ever saw,
683 * including labels, stabs strings, ascii strings, etc.
684 * This is slightly wasteful.
5178805d 685 */
ec43bca4
RH
686 i = 0;
687 while((nread = read(strfile->_file, rbuf, sizeof(rbuf))) > 0){
688 if (i == 0){
ec43bca4 689 ((int *)rbuf)[0] = strfilepos;
ad67d5e5 690 }
ec43bca4
RH
691 bwrite(rbuf, nread, symfile);
692 i++;
5178805d 693 }
5178805d 694}