Annotation of researchv9/jerq/sgs/strip/buildtmp.c, revision 1.1

1.1     ! root        1: /* UNIX HEADER */
        !             2: #include       <stdio.h>
        !             3: 
        !             4: /* COMMON SGS HEADERS */
        !             5: #include       "filehdr.h"
        !             6: #include       "ldfcn.h"
        !             7: 
        !             8: /* STRIP HEADER */
        !             9: #include       "defs.h"
        !            10: 
        !            11: 
        !            12:     /*  buildtmp(filename, filehead)
        !            13:      *
        !            14:      *  Directs the building of the stripped temporary file.
        !            15:      *  Copies the optional header, section headers, section contents, and
        !            16:      *  relocation or symbol table information (depending on lflag, xflag or
        !            17:      *  bflag) to the temporary file.
        !            18:      *
        !            19:      *  calls:
        !            20:      *      - cpyopthdr( ) to copy the optional header
        !            21:      *      - cpyscnhdrs( ) to copy the section headers (update them too)
        !            22:      *      - cpyscns( ) to copy the section contents
        !            23:      *
        !            24:      *         - if lflag is ON
        !            25:      *                 - cpyreloc( ) to copy relocation information
        !            26:      *                 - copysyms( ) to copy all symbols (update them too)
        !            27:      *         - if sflag is ON
        !            28:      *                 - cpyexts( ) to copy external and static symbols and
        !            29:      *                         fix up the line number entries
        !            30:      *                 - newreloc( ) to copy and fix up relocation entries
        !            31:      *                 - cpylnums( ) to copy and fix up the line number entries
        !            32:      *         - if xflag is ON
        !            33:      *                 - cpyexts( ) to copy external and static symbols
        !            34:      *         - if bflag is ON
        !            35:      *                 - cpyexts( ) to copy external, static, .bb, .eb, .bf,
        !            36:      *                   .ef symbols
        !            37:      *         - if rflag is ON
        !            38:      *                 - if local symbols are already stripped
        !            39:      *                         - cpyreloc( ) to copy relocation information
        !            40:      *                         - cpysyms to copy all symbols
        !            41:      *                 - else
        !            42:      *                         - cpyexts( ) to copy external and static symbols
        !            43:      *                         - newreloc( ) to copy and fix up relocation entries
        !            44:      *
        !            45:      *      - error(file, message, level) if anything goes wrong
        !            46:      *
        !            47:      *  buildtmp( ) keeps track of the new location of the symbol table in a
        !            48:      *  partially stripped (lflag, xflag, bflag) file
        !            49:      *
        !            50:      *  returns SUCCESS or FAILURE
        !            51:      */
        !            52: 
        !            53: 
        !            54: int
        !            55: buildtmp(filename, filehead)
        !            56: 
        !            57: char   *filename;
        !            58: FILHDR *filehead;
        !            59: 
        !            60: {
        !            61:     /* STRIP FUNCTIONS CALLED */
        !            62:     extern int         cpyopthdr( ),
        !            63:                        cpyscnhdrs( ),
        !            64:                        copysyms( );
        !            65:     extern long                copyscns( ),
        !            66:                        cpyreloc( ),
        !            67:                        cpylnums( ),
        !            68:                        newreloc( ),
        !            69:                        copyexts( );
        !            70:     extern             error( );
        !            71: 
        !            72:     /* EXTERNAL VARIABLES USED */
        !            73:     extern LDFILE      *ldptr;
        !            74:     extern FILE                *strp2;
        !            75:     extern FILE                *strp1;
        !            76:     extern char                tmpnam1[ ];
        !            77:     extern int         lflag,
        !            78:                        xflag,
        !            79:                        bflag,
        !            80:                        sflag,
        !            81:                        rflag;
        !            82: 
        !            83:     if (filehead->f_opthdr != 0) {
        !            84:        if (cpyopthdr( ) != SUCCESS) {
        !            85:            error(filename, "cannot copy optional header", 2);
        !            86:            return(FAILURE);
        !            87:        }
        !            88:     }
        !            89: 
        !            90:     if (cpyscnhdrs( ) != SUCCESS) {
        !            91:        error(filename, "cannot copy section headers", 2);
        !            92:        return(FAILURE);
        !            93:     }
        !            94: 
        !            95:     if ((filehead->f_symptr = copyscns( )) == ERROR) {
        !            96:        error(filename, "cannot copy sections", 2);
        !            97:        return(FAILURE);
        !            98:     }
        !            99: 
        !           100:        if ( lflag ) {
        !           101:                if ((filehead->f_flags & F_RELFLG) == 0) {
        !           102:                        if ((filehead->f_symptr = cpyreloc(filehead->f_symptr)) == ERROR) {
        !           103:                                error(filename, "cannot copy relocation information", 2);
        !           104:                                return(FAILURE);
        !           105:                        }
        !           106:                }
        !           107:                if (copysyms( ) != SUCCESS) {
        !           108:                        error( filename, "cannot copy symbol table", 2 );
        !           109:                        return( FAILURE );
        !           110:                }
        !           111: 
        !           112:        } else if ( sflag) {
        !           113:                if ((filehead->f_nsyms = copyexts( filename )) == ERROR) {
        !           114:                        error( filename, "cannot copy external symbols", 2);
        !           115:                        return( FAILURE );
        !           116:                }
        !           117:                if ( !(filehead->f_flags & F_RELFLG) && ((filehead->f_symptr = newreloc( filehead->f_symptr )) == ERROR)) {
        !           118:                        error( filename, "cannot copy relocation entries", 2 );
        !           119:                        return( FAILURE );
        !           120:                }
        !           121:                if ( !(filehead->f_flags & F_LNNO) && ((filehead->f_symptr = cpylnums( filehead->f_symptr )) == ERROR)) {
        !           122:                        error( filename, "cannot copy line numbers", 2 );
        !           123:                        return( FAILURE );
        !           124:                }
        !           125: 
        !           126:        } else if (xflag || bflag) {
        !           127:                if ((filehead->f_nsyms = copyexts(filename)) == ERROR) {
        !           128:                        error(filename, "cannot copy external symbols", 3);
        !           129:                        return(FAILURE);
        !           130:                }
        !           131: 
        !           132:        } else if (rflag ) {
        !           133:                if (filehead->f_flags & F_LSYMS) {
        !           134:                        if ((filehead->f_symptr = cpyreloc( filehead->f_symptr )) == ERROR ) {
        !           135:                                error( filename, "cannot copy relocation information", 2);
        !           136:                                return( FAILURE );
        !           137:                        }
        !           138:                        if (copysyms( ) != SUCCESS) {
        !           139:                                error( filename, "cannot copy symbol table", 2);
        !           140:                                return( FAILURE );
        !           141:                        }
        !           142:                } else {
        !           143:                        if ((filehead->f_nsyms = copyexts(filename)) == ERROR) {
        !           144:                                error(filename,"cannot copy external symbols", 3);
        !           145:                                return(FAILURE);
        !           146:                        }
        !           147:                        if((filehead->f_flags & F_RELFLG) == 0) {
        !           148:                                if ((filehead->f_symptr = newreloc(filehead->f_symptr)) == ERROR) {
        !           149:                                        error(filename, "cannot copy relocation information",2); 
        !           150:                                        return(FAILURE);
        !           151:                                }
        !           152:                        }
        !           153:                }
        !           154: 
        !           155:        } else {
        !           156:                filehead->f_symptr = 0L;
        !           157:                filehead->f_nsyms = 0L;
        !           158:        }
        !           159: 
        !           160:     return(SUCCESS);
        !           161: }
        !           162: /*
        !           163:  *     @(#)buildtmp.c  1.5 11/4/83;
        !           164:  */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.