cleanup from Chris Torek
[unix-history] / usr / src / old / as.vax / assyms.c
index f67175c..166cff3 100644 (file)
@@ -1,8 +1,11 @@
 /*
 /*
- *     Copyright (c) 1982 Regents of the University of California
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
  */
  */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)assyms.c 4.7 %G%";
+static char sccsid[] = "@(#)assyms.c   5.2 (Berkeley) %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -42,14 +45,8 @@ int  nlabels;        /* number of label entries */
 
 /*
  *     Managers of the symbol literal storage.
 
 /*
  *     Managers of the symbol literal storage.
- *     If we have flexible names, then we allocate BUFSIZ long
- *     string, and pack strings into that.  Otherwise, we allocate
- *     symbol storage in fixed hunks NCPS long when we allocate space
- *     for other symbol attributes.
  */
  */
-#ifdef FLEXNAMES
 struct strpool         *strplhead = 0;
 struct strpool         *strplhead = 0;
-#endif FLEXNAMES
 
 symtabinit()
 {
 
 symtabinit()
 {
@@ -57,9 +54,7 @@ symtabinit()
        alloctail = 0;
        nextsym = 0;
        symsleft = 0;
        alloctail = 0;
        nextsym = 0;
        symsleft = 0;
-#ifdef FLEXNAMES
        strpoolalloc();         /* get the first strpool storage area */
        strpoolalloc();         /* get the first strpool storage area */
-#endif FLEXNAMES
        htab = 0;
        htaballoc();            /* get the first part of the hash table */
 }
        htab = 0;
        htaballoc();            /* get the first part of the hash table */
 }
@@ -77,12 +72,8 @@ syminstall()
        for (i = 0; i < NINST; i++)
                itab[i] = (Iptr*)BADPOINT;
 
        for (i = 0; i < NINST; i++)
                itab[i] = (Iptr*)BADPOINT;
 
-#ifdef FLEXNAMES
-       for (ip = (Iptr)instab; ip->s_name != 0; ip++) {
-#else not FLEXNAMES
-       for (ip = (Iptr)instab; ip->s_name[0] != '\0'; ip++){
-#endif not FLEXNAMES
-               p1 = ip->s_name;
+       for (ip = (Iptr)instab; FETCHNAME(ip)[0]; ip++) {
+               p1 = FETCHNAME(ip);
                p2 = yytext;
                while (*p2++ = *p1++);
                hp = lookup(0);         /* 0 => don't install this*/
                p2 = yytext;
                while (*p2++ = *p1++);
                hp = lookup(0);         /* 0 => don't install this*/
@@ -104,7 +95,11 @@ syminstall()
        }
 }      /*end of syminstall*/
 
        }
 }      /*end of syminstall*/
 
-
+#define ISLABEL(sp) \
+       (   (!savelabels) \
+        && (sp->s_tag == LABELID) \
+        && (STRPLACE(sp) & STR_CORE) \
+        && (FETCHNAME(sp)[0] == 'L'))
 /*
  *     Assign final values to symbols,
  *     and overwrite the index field with its relative position in
 /*
  *     Assign final values to symbols,
  *     and overwrite the index field with its relative position in
@@ -141,16 +136,11 @@ freezesymtab()
                        hdr.a_bss += bs;
                }
           assignindex:
                        hdr.a_bss += bs;
                }
           assignindex:
-               if (    (sp->s_name[0] != 'L')
-                    || (sp->s_tag != LABELID)
-                    || savelabels
-                    )                  /*then, we will write it later on*/
-                               sp->s_index = relpos++;
+               if (!ISLABEL(sp))
+                       sp->s_index = relpos++;
        }
 }
 
        }
 }
 
-
-
 /*
  *     For all of the stabs that had their final value undefined during pass 1
  *     and during pass 2 assign a final value.
 /*
  *     For all of the stabs that had their final value undefined during pass 1
  *     and during pass 2 assign a final value.
@@ -158,16 +148,27 @@ freezesymtab()
  *     when we constsructed the sorted symbol table.
  *     Iteration order doesn't matter.
  */
  *     when we constsructed the sorted symbol table.
  *     Iteration order doesn't matter.
  */
-stabfix() {
+
+stabfix()
+{
        register struct symtab *sp, **cosp;
        register struct symtab *p;
        
        SYMITERATE(cosp, sp){
                if(sp->s_ptype && (sp->s_type & STABFLAG)) {    
                        p = sp->s_dest; 
        register struct symtab *sp, **cosp;
        register struct symtab *p;
        
        SYMITERATE(cosp, sp){
                if(sp->s_ptype && (sp->s_type & STABFLAG)) {    
                        p = sp->s_dest; 
-                       sp->s_value = p->s_value;       
+/* 
+ * STABFLOATING indicates that the offset has been saved in s_desc, s_other
+ */
+                       if(sp->s_tag == STABFLOATING) {
+                         sp->s_value = ( ( ((unsigned char) sp->s_other) << 16)                                        | ( (unsigned short) sp->s_desc )  );
+                         sp->s_value = sp->s_value + p->s_value;
+                       }
+                       else sp->s_value = p->s_value;
                        sp->s_index = p->s_index;
                        sp->s_type = p->s_type;
                        sp->s_index = p->s_index;
                        sp->s_type = p->s_type;
+
+              
                }
        }
 }
                }
        }
 }
@@ -216,7 +217,6 @@ struct symtab *symalloc()
        return(nextsym++);
 }
 
        return(nextsym++);
 }
 
-#ifdef FLEXNAMES
 strpoolalloc()
 {
        register        struct  strpool *new;
 strpoolalloc()
 {
        register        struct  strpool *new;
@@ -226,7 +226,6 @@ strpoolalloc()
        new->str_next = strplhead;
        strplhead = new;
 }
        new->str_next = strplhead;
        strplhead = new;
 }
-#endif FLEXNAMES
 
 symcmp(Pptr, Qptr)
        struct symtab **Pptr, **Qptr;
 
 symcmp(Pptr, Qptr)
        struct symtab **Pptr, **Qptr;
@@ -321,17 +320,10 @@ dumpsymtab()
        for (segno = 0; segno < NLOC + NLOC; segno++){
                printf("Segment number: %d\n", segno);
                SEGITERATE(segno, 0, 0, cosp, sp, ub, ++){
        for (segno = 0; segno < NLOC + NLOC; segno++){
                printf("Segment number: %d\n", segno);
                SEGITERATE(segno, 0, 0, cosp, sp, ub, ++){
-#ifdef FLEXNAMES
                        printf("\tSeg: %d \"%s\" value: %d index: %d tag %s\n",
                        printf("\tSeg: %d \"%s\" value: %d index: %d tag %s\n",
-                               segno, sp->s_name,
-                               sp->s_value, sp->s_index,
-                               tagstring(sp->s_tag));
-#else not FLEXNAMES
-                       printf("\tSeg: %d \"%*.*s\" value: %d index: %d tag %s\n",
-                               segno, NCPS, NCPS, sp->s_name,
+                               segno, FETCHNAME(sp),
                                sp->s_value, sp->s_index,
                                tagstring(sp->s_tag));
                                sp->s_value, sp->s_index,
                                tagstring(sp->s_tag));
-#endif not FLEXNAMES
                        printf("\t\ttype: %d jxbump %d jxfear: %d\n",
                                sp->s_type, sp->s_jxbump, sp->s_jxfear);
                }
                        printf("\t\ttype: %d jxbump %d jxfear: %d\n",
                                sp->s_type, sp->s_jxbump, sp->s_jxfear);
                }
@@ -359,7 +351,7 @@ char *tagstring(tag)
                case OKTOBUMP:          return("oktobump");
                case ISET:              return("iset");
                case ILSYM:             return("ilsym");
                case OKTOBUMP:          return("oktobump");
                case ISET:              return("iset");
                case ILSYM:             return("ilsym");
-               default:                sprintf(tagbuff,"%d", tag);
+               default:                (void)sprintf(tagbuff,"%d", tag);
                                        return(tagbuff);
        }
 }
                                        return(tagbuff);
        }
 }
@@ -399,10 +391,10 @@ struct symtab **lookup(instflg)
        register char           *to;
        register        int     len;
        register        int     nprobes;
        register char           *to;
        register        int     len;
        register        int     nprobes;
-       static   struct hashdallop *hdallop;
-       static   struct symtab  **emptyslot;
-       static   struct hashdallop *emptyhd;
-       static   struct symtab  **hp_ub;
+       static  struct  hashdallop *hdallop;
+       static  struct  symtab  **emptyslot;
+       static  struct  hashdallop *emptyhd;
+       static  struct  symtab  **hp_ub;
 
        emptyslot = 0;
        for (nprobes = 0, from = yytext;
 
        emptyslot = 0;
        for (nprobes = 0, from = yytext;
@@ -425,24 +417,13 @@ struct symtab **lookup(instflg)
                                nprobes += 2)
                {
                        from = yytext;
                                nprobes += 2)
                {
                        from = yytext;
-                       to = (*hp)->s_name;
-#ifndef FLEXNAMES
-                       for (len = 0; (len<NCPS) && *from; len++)
-                               if (*from++ != *to++)
-                                       goto nextprobe;
-                       if (len >= NCPS)        /*both are maximal length*/
-                               return(hp);
-                       if (*to == 0)           /*assert *from == 0*/
-                               return(hp);
-#else FLEXNAMES
+                       to = FETCHNAME(*hp);
                        while (*from && *to)
                                if (*from++ != *to++)
                                        goto nextprobe;
                        if (*to == *from)       /*assert both are == 0*/
                                return(hp);
                        while (*from && *to)
                                if (*from++ != *to++)
                                        goto nextprobe;
                        if (*to == *from)       /*assert both are == 0*/
                                return(hp);
-#endif FLEXNAMES
-
-       nextprobe: ;
+               nextprobe: ;
                }
                if (*hp == 0 && emptyslot == 0 &&
                    hdallop->h_nused < HASHCLOGGED) {
                }
                if (*hp == 0 && emptyslot == 0 &&
                    hdallop->h_nused < HASHCLOGGED) {
@@ -461,44 +442,59 @@ struct symtab **lookup(instflg)
        if (instflg) {
                *hp = symalloc();
                hdallop->h_nused++;
        if (instflg) {
                *hp = symalloc();
                hdallop->h_nused++;
-#ifndef FLEXNAMES
-               for(len = 0, from = yytext, to = (*hp)->s_name; (len<NCPS); len++)
-                       if ((*to++ = *from++) == '\0')
-                               break;
-#else FLEXNAMES
-               for (from = yytext, len = 1; *from++; len++)
+               for (from = yytext, len = 0; *from++; len++)
                        continue;
                        continue;
-               if (len >= (STRPOOLDALLOP - strplhead->str_nalloc))
-                       strpoolalloc();
-               for ( (*hp)->s_name = to = strplhead->str_names + strplhead->str_nalloc, from = yytext;
-                    ( (*to++ = *from++) != '\0'); )
-                       continue;
-               strplhead->str_nalloc += len;
-#endif FLEXNAMES
+               (*hp)->s_name = (char *)savestr(yytext, len + 1, STR_BOTH);
        }
        return(hp);
 }      /*end of lookup*/
        }
        return(hp);
 }      /*end of lookup*/
-
-#ifdef FLEXNAMES
-char *savestr(str)
-       char *str;
+/*
+ *     save a string str with len in the places indicated by place
+ */
+struct strdesc *savestr(str, len, place)
+       char    *str;
+       int     len;
+       int     place;
 {
 {
-       register int len;
-       register char *from, *to;
-       char *res;
-
-       for (from = str, len = 1; *from++; len++)
-               continue;
-       if (len >= (STRPOOLDALLOP - strplhead->str_nalloc))
+       reg     struct  strdesc *res;
+               int     tlen;
+       /*
+        *      Compute the total length of the record to live in core
+        */
+       tlen = sizeof(struct strdesc) - sizeof(res->sd_string);
+       if (place & STR_CORE)
+               tlen += len;
+       /*
+        *      See if there is enough space for the record,
+        *      and allocate the record.
+        */
+       if (tlen >= (STRPOOLDALLOP - strplhead->str_nalloc))
                strpoolalloc();
                strpoolalloc();
-       for ( res = to = strplhead->str_names + strplhead->str_nalloc, from = str;
-                    ( (*to++ = *from++) != '\0'); )
-                       continue;
-       strplhead->str_nalloc += len;
-       return (res);
+       res = (struct strdesc *)(strplhead->str_names + strplhead->str_nalloc);
+       /*
+        *      Save the string information that is always present
+        */
+       res->sd_stroff = strfilepos;
+       res->sd_strlen = len;
+       res->sd_place = place;
+       /*
+        *      Now, save the string itself.  If str is null, then
+        *      the characters have already been dumped to the file
+        */
+       if ((place & STR_CORE) && str)
+               movestr(res[0].sd_string, str, len);
+       if (place & STR_FILE){
+               if (str){
+                       fwrite(str, 1, len, strfile);
+               }
+               strfilepos += len;
+       }
+       /*
+        *      Adjust the in core string pool size
+        */
+       strplhead->str_nalloc += tlen;
+       return(res);
 }
 }
-#endif FLEXNAMES
-
 /*
  *     The relocation information is saved internally in an array of
  *     lists of relocation buffers.  The relocation buffers are
 /*
  *     The relocation information is saved internally in an array of
  *     lists of relocation buffers.  The relocation buffers are
@@ -540,7 +536,7 @@ outrel(xp, reloc_how)
 {
        struct          relocation_info reloc;
        register        int     x_type_mask;    
 {
        struct          relocation_info reloc;
        register        int     x_type_mask;    
-       int             pcrel;
+                       int     pcrel;
 
        x_type_mask = xp->e_xtype & ~XFORW;
        pcrel = reloc_how & RELOC_PCREL;
 
        x_type_mask = xp->e_xtype & ~XFORW;
        pcrel = reloc_how & RELOC_PCREL;
@@ -646,91 +642,88 @@ int sizesymtab()
 {
        return (sizeof (struct nlist) * NOUTSYMS);
 }
 {
        return (sizeof (struct nlist) * NOUTSYMS);
 }
-
-#ifdef FLEXNAMES
-/*
- *     We write out the flexible length character strings for  names
- *     in two stages.
- *     1)      We have always! maintain a fixed sized name list entry;
- *     the string is indexed by a four byte quantity from the beginning
- *     of the string pool area.  Index 0 is reserved, and indicates
- *     that there is no associated string. The first valid index is 4.
- *     2)       We concatenate together and write all of the strings
- *     in the string pool at the end of the name list. The first 
- *     four bytes in the string pool are indexed only by 0 (see above);
- *     they contain the total number of bytes in the string pool.
- */
-#endif FLEXNAMES
-
 /*
  *     Write out n symbols to file f, beginning at p
  *     ignoring symbols that are obsolete, jxxx instructions, and
  *     possibly, labels
  */
 /*
  *     Write out n symbols to file f, beginning at p
  *     ignoring symbols that are obsolete, jxxx instructions, and
  *     possibly, labels
  */
-
 int symwrite(symfile)
        BFILE *symfile;
 {
 int symwrite(symfile)
        BFILE *symfile;
 {
-       int     symsout;                        /*those actually written*/
-       int     symsdesired = NOUTSYMS;
-       register        struct  symtab *sp, *ub;
-#ifdef FLEXNAMES
-       char            *name;                  /* temp to save the name */
-       long            stroff  = sizeof (stroff);
+               int     symsout;                /*those actually written*/
+               int     symsdesired = NOUTSYMS;
+       reg     struct  symtab *sp, *ub;
+               char    *name;                  /* temp to save the name */
+               int     totalstr;
        /*
         *      We use sp->s_index to hold the length of the
         *      name; it isn't used for anything else
         */
        /*
         *      We use sp->s_index to hold the length of the
         *      name; it isn't used for anything else
         */
-#endif FLEXNAMES
-
        register        struct  allocbox        *allocwalk;
 
        symsout = 0;
        register        struct  allocbox        *allocwalk;
 
        symsout = 0;
-       DECLITERATE(allocwalk, sp, ub)
-       {
+       totalstr = sizeof(totalstr);
+       DECLITERATE(allocwalk, sp, ub) {
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
-               if ((sp->s_name[0] == 'L') && (sp->s_tag == LABELID) && !savelabels)
+               if (ISLABEL(sp))
                        continue;
                symsout++;
                        continue;
                symsout++;
-
-#ifdef FLEXNAMES
                name = sp->s_name;              /* save pointer */
                name = sp->s_name;              /* save pointer */
-               if ( (sp->s_index = strlen(sp->s_name)) != 0){
-                       sp->s_nmx = stroff;     /* clobber pointer */
-                       stroff += sp->s_index + 1;
+               /*
+                *      the length of the symbol table string
+                *      always includes the trailing null;
+                *      blast the pointer to its a.out value.
+                */
+               if (sp->s_name && (sp->s_index = STRLEN(sp))){
+                       sp->s_nmx = totalstr;
+                       totalstr += sp->s_index;
                } else {
                } else {
-                       sp->s_nmx = 0;          /* clobber pointer */
+                       sp->s_nmx = 0;
                }
                }
-#endif
-               sp->s_type = (sp->s_ptype != 0) ? sp->s_ptype : (sp->s_type & (~XFORW));
+               if (sp->s_ptype != 0)
+                       sp->s_type = sp->s_ptype;
+               else
+                       sp->s_type = (sp->s_type & (~XFORW));
                if (readonlydata && (sp->s_type&~N_EXT) == N_DATA)
                        sp->s_type = N_TEXT | (sp->s_type & N_EXT);
                bwrite((char *)&sp->s_nm, sizeof (struct nlist), symfile);
                if (readonlydata && (sp->s_type&~N_EXT) == N_DATA)
                        sp->s_type = N_TEXT | (sp->s_type & N_EXT);
                bwrite((char *)&sp->s_nm, sizeof (struct nlist), symfile);
-#ifdef FLEXNAMES
                sp->s_name = name;              /* restore pointer */
                sp->s_name = name;              /* restore pointer */
-#endif FLEXNAMES
        }
        if (symsout != symsdesired)
                yyerror("INTERNAL ERROR: Wrote %d symbols, wanted to write %d symbols\n",
                        symsout, symsdesired);
        }
        if (symsout != symsdesired)
                yyerror("INTERNAL ERROR: Wrote %d symbols, wanted to write %d symbols\n",
                        symsout, symsdesired);
-#ifdef FLEXNAMES
        /*
        /*
-        *      Pass 2 through the string pool
+        *      Construct the string pool from the symbols that were written,
+        *      possibly fetching from the string file if the string
+        *      is not core resident.
         */
         */
+       bwrite(&totalstr, sizeof(totalstr), symfile);
        symsout = 0;
        symsout = 0;
-       bwrite((char *)&stroff, sizeof (stroff), symfile);
-       stroff = sizeof (stroff);
-       symsout = 0;
-       DECLITERATE(allocwalk, sp, ub)
-       {
+       DECLITERATE(allocwalk, sp, ub) {
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
-               if ((sp->s_name[0] == 'L') && (sp->s_tag == LABELID) && !savelabels)
+               if (ISLABEL(sp))
                        continue;
                        continue;
-               sp->s_index = strlen(sp->s_name);
-               if (sp->s_index)
-                       bwrite(sp->s_name, sp->s_index + 1, symfile);
+               symsout++;
+               if (STRLEN(sp) > 0){
+                if (STRPLACE(sp) & STR_CORE){
+                       bwrite(FETCHNAME(sp), STRLEN(sp), symfile);
+                } else if (STRPLACE(sp) & STR_FILE){
+                       char    rbuf[2048];
+                       int     left, nread;
+                       fseek(strfile, STROFF(sp), 0);
+                       for (left = STRLEN(sp); left > 0; left -= nread){
+                               nread = fread(rbuf, sizeof(char),
+                                       min(sizeof(rbuf), left), strfile);
+                               if (nread == 0)
+                                       break;
+                               bwrite(rbuf, nread, symfile);
+                       }
+                }
+               }
        }
        }
-#endif FLEXNAMES
+       if (symsout != symsdesired)
+               yyerror("INTERNAL ERROR: Wrote %d strings, wanted %d\n",
+                       symsout, symsdesired);
 }
 }