From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9601050213.AA12790@ives.amt.tay1.dec.com> Date: Thu, 4 Jan 1996 21:13:54 -0500 (EST) From: Jim Paradis Subject: Re: which quickstrip ? In-Reply-To: <199601041453.JAA21724@postman.osf.org> > I am also attempting to rebuild a Linux/Alpha kernel for the first time, > here from the BLADE_0.3 distribution. The Makefile in arch/alpha/boot > fails because the `quickstrip' command is not found. Should I use the > BLADE_0.3 /usr/bin/strip instead ?? No, do not use /usr/bin/strip... it does a bit of "rearranging" of the executable image such that the MILO loader no longer loads it correctly. Here's the source for quickstrip if you don't have it already... it's really simple and straightforward... ------------------------------- cut here ------------------------------------ #include #include #include #include struct filehdr { unsigned short f_magic; /* Magic number (must be ALPHAMAGIC) */ unsigned short f_nscns; /* Number of sections */ int f_timdat; /* Time/date of creation */ int f_symptr; /* Pointer to symbolic header */ int f_symptr_pad; /* Hi half of symptr quadword SBZ */ int f_nsyms; unsigned short f_opthdr; /* sozeof optional header */ unsigned short f_flags; /* flags */ }; /* Usage: quickstrip infile [outfile] */ #define BUFSIZE 1024 char iobuf[BUFSIZE]; #define LITTLE_MAGIC 0x0183 #define BIG_MAGIC 0x8301 main(int argc, char ** argv) { if(argc == 2) { strip_in_place(argv[1]); } else if(argc == 3) { strip_to_output(argv[1], argv[2]); } else { printf("Usage: %s infile [outfile]\n", argv[0]); exit(0); } } strip_in_place(char * filename) { int infile; struct filehdr fh; int big_endian = 0; infile = open(filename, O_RDWR); if(infile < 0) { perror(filename); exit(0); } if(read(infile, &fh, sizeof(struct filehdr)) != sizeof(struct filehdr)) { perror("read"); exit(0); } if(fh.f_magic == BIG_MAGIC) { big_endian = 1; swap_fh(&fh); } #ifdef DEBUG printf("quickstrip: filhdr contents:\n"); printf(" f_magic: 0x%x\n", fh.f_magic); printf(" f_nscns: 0x%x\n", fh.f_nscns); printf(" f_timdat: 0x%x\n", fh.f_timdat); printf(" f_symptr: 0x%x\n", fh.f_symptr); printf(" f_symptr_pad: 0x%x\n", fh.f_symptr_pad); printf(" f_nsyms: 0x%x\n", fh.f_nsyms); printf(" f_opthdr: 0x%x\n", fh.f_opthdr); printf(" f_flags: 0x%x\n", fh.f_flags); #endif if(fh.f_symptr) { ftruncate(infile, fh.f_symptr); printf("%s truncated at %d\n", filename, fh.f_symptr); fh.f_symptr = 0; lseek(infile, 0, SEEK_SET); if(big_endian) { swap_fh(fh); } write(infile, &fh, sizeof(struct filehdr)); } else { printf("It looks like %s is already stripped!\n", filename); } close(infile); } strip_to_output(char * name1, char * name2) { int infile; int outfile; struct filehdr fh; struct stat st; int bytesleft; int iosize; int nwritten = 0; int big_endian = 0; infile = open(name1, O_RDONLY); if(infile < 0) { perror(name1); exit(0); } if(read(infile, &fh, sizeof(struct filehdr)) != sizeof(struct filehdr)) { perror("read"); exit(0); } if(fh.f_magic == BIG_MAGIC) { big_endian = 1; swap_fh(&fh); } #ifdef DEBUG printf("quickstrip: filhdr contents:\n"); printf(" f_magic: 0x%x\n", fh.f_magic); printf(" f_nscns: 0x%x\n", fh.f_nscns); printf(" f_timdat: 0x%x\n", fh.f_timdat); printf(" f_symptr: 0x%x\n", fh.f_symptr); printf(" f_symptr_pad: 0x%x\n", fh.f_symptr_pad); printf(" f_nsyms: 0x%x\n", fh.f_nsyms); printf(" f_opthdr: 0x%x\n", fh.f_opthdr); printf(" f_flags: 0x%x\n", fh.f_flags); #endif if(!fh.f_symptr) { printf("Looks as though %s is already stripped. Doing nothing.\n", name1); exit(0); } fstat(infile, &st); outfile = open(name2, O_WRONLY|O_CREAT, st.st_mode); if(outfile < 0) { perror(name2); close(infile); exit(0); } bytesleft = fh.f_symptr - sizeof(struct filehdr); fh.f_symptr = 0; if(big_endian) { swap_fh(&fh); } write(outfile, &fh, sizeof(struct filehdr)); while(bytesleft > 0) { iosize = (bytesleft > BUFSIZE) ? BUFSIZE : bytesleft; read(infile, iobuf, iosize); write(outfile, iobuf, iosize); nwritten += iosize; bytesleft -= iosize; } printf("%d bytes written to %s\n", nwritten, name2); close(outfile); } unsigned short swap16(unsigned short s) { return((unsigned short)( ((s << 8) & 0xff00) | ((s >> 8) & 0x00ff))); } unsigned int swap32(unsigned int i) { return((unsigned int)( ((i << 24) & 0xff000000) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | ((i >> 24) & 0x000000ff)) ); } swap_fh(struct filehdr *fh) { fh->f_magic = swap16(fh->f_magic); fh->f_nscns = swap16(fh->f_nscns); fh->f_timdat = swap32(fh->f_timdat); fh->f_symptr = swap32(fh->f_symptr); fh->f_symptr_pad = swap32(fh->f_symptr_pad); fh->f_nsyms = swap32(fh->f_nsyms); fh->f_opthdr = swap16(fh->f_opthdr); fh->f_flags = swap16(fh->f_flags); }