Print this page
5595 libzpool won't build with a studio primary


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 /*
  29  * Given a file containing sections with stabs data, convert the stabs data to
  30  * CTF data, and replace the stabs sections with a CTF section.
  31  */
  32 
  33 #include <stdio.h>
  34 #include <stdlib.h>
  35 #include <unistd.h>
  36 #include <signal.h>
  37 #include <string.h>
  38 #include <fcntl.h>
  39 #include <libgen.h>
  40 #include <errno.h>
  41 #include <assert.h>
  42 
  43 #include "ctftools.h"
  44 #include "memory.h"
  45 
  46 const  char *progname;
  47 int debug_level = DEBUG_LEVEL;


 133                 }
 134 
 135                 rc = 0;
 136         } else {
 137                 rc = 1;
 138         }
 139 
 140         (void) elf_end(elf);
 141         (void) close(fd);
 142 
 143         return (rc);
 144 }
 145 
 146 int
 147 main(int argc, char **argv)
 148 {
 149         tdata_t *filetd, *mstrtd;
 150         char *label = NULL;
 151         int verbose = 0;
 152         int ignore_non_c = 0;
 153         int keep_stabs = 0;
 154         int c;
 155 
 156         sighold(SIGINT);
 157         sighold(SIGQUIT);
 158         sighold(SIGTERM);
 159 
 160         progname = basename(argv[0]);
 161 
 162         if (getenv("CTFCONVERT_DEBUG_LEVEL"))
 163                 debug_level = atoi(getenv("CTFCONVERT_DEBUG_LEVEL"));
 164         if (getenv("CTFCONVERT_DEBUG_PARSE"))
 165                 debug_parse = atoi(getenv("CTFCONVERT_DEBUG_PARSE"));
 166 
 167         while ((c = getopt(argc, argv, ":l:L:o:givs")) != EOF) {
 168                 switch (c) {
 169                 case 'l':
 170                         label = optarg;
 171                         break;
 172                 case 'L':
 173                         if ((label = getenv(optarg)) == NULL)
 174                                 label = CTF_DEFAULT_LABEL;
 175                         break;
 176                 case 'o':
 177                         outfile = optarg;
 178                         break;
 179                 case 's':
 180                         dynsym = CTF_USE_DYNSYM;
 181                         break;
 182                 case 'i':
 183                         ignore_non_c = 1;
 184                         break;
 185                 case 'g':
 186                         keep_stabs = CTF_KEEP_STABS;
 187                         break;
 188                 case 'v':
 189                         verbose = 1;
 190                         break;
 191                 default:
 192                         usage();
 193                         exit(2);
 194                 }
 195         }
 196 
 197         if (getenv("STRIPSTABS_KEEP_STABS") != NULL)
 198                 keep_stabs = CTF_KEEP_STABS;
 199 
 200         if (argc - optind != 1 || label == NULL) {
 201                 usage();
 202                 exit(2);
 203         }
 204 
 205         infile = argv[optind];
 206         if (access(infile, R_OK) != 0)
 207                 terminate("Can't access %s", infile);
 208 
 209         /*
 210          * Upon receipt of a signal, we want to clean up and exit.  Our
 211          * primary goal during cleanup is to restore the system to a state
 212          * such that a subsequent make will eventually cause this command to
 213          * be re-run.  If we remove the input file (which we do if we get a
 214          * signal and the user didn't specify a separate output file), make
 215          * will need to rebuild the input file, and will then need to re-run
 216          * ctfconvert, which is what we want.
 217          */
 218         set_terminate_cleanup(terminate_cleanup);
 219 


 223 
 224         filetd = tdata_new();
 225 
 226         if (!file_read(filetd, infile, ignore_non_c))
 227                 terminate("%s doesn't have type data to convert\n", infile);
 228 
 229         if (verbose)
 230                 iidesc_stats(filetd->td_iihash);
 231 
 232         mstrtd = tdata_new();
 233         merge_into_master(filetd, mstrtd, NULL, 1);
 234 
 235         tdata_label_add(mstrtd, label, CTF_LABEL_LASTIDX);
 236 
 237         /*
 238          * If the user supplied an output file that is different from the
 239          * input file, write directly to the output file.  Otherwise, write
 240          * to a temporary file, and replace the input file when we're done.
 241          */
 242         if (outfile && strcmp(infile, outfile) != 0) {
 243                 write_ctf(mstrtd, infile, outfile, dynsym | keep_stabs);
 244         } else {
 245                 char *tmpname = mktmpname(infile, ".ctf");
 246 
 247                 write_ctf(mstrtd, infile, tmpname, dynsym | keep_stabs);
 248                 if (rename(tmpname, infile) != 0)
 249                         terminate("Couldn't rename temp file %s", tmpname);
 250                 free(tmpname);
 251         }
 252 
 253         return (0);
 254 }


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 


  26 /*
  27  * Given a file containing sections with stabs data, convert the stabs data to
  28  * CTF data, and replace the stabs sections with a CTF section.
  29  */
  30 
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <unistd.h>
  34 #include <signal.h>
  35 #include <string.h>
  36 #include <fcntl.h>
  37 #include <libgen.h>
  38 #include <errno.h>
  39 #include <assert.h>
  40 
  41 #include "ctftools.h"
  42 #include "memory.h"
  43 
  44 const  char *progname;
  45 int debug_level = DEBUG_LEVEL;


 131                 }
 132 
 133                 rc = 0;
 134         } else {
 135                 rc = 1;
 136         }
 137 
 138         (void) elf_end(elf);
 139         (void) close(fd);
 140 
 141         return (rc);
 142 }
 143 
 144 int
 145 main(int argc, char **argv)
 146 {
 147         tdata_t *filetd, *mstrtd;
 148         char *label = NULL;
 149         int verbose = 0;
 150         int ignore_non_c = 0;

 151         int c;
 152 
 153         sighold(SIGINT);
 154         sighold(SIGQUIT);
 155         sighold(SIGTERM);
 156 
 157         progname = basename(argv[0]);
 158 
 159         if (getenv("CTFCONVERT_DEBUG_LEVEL"))
 160                 debug_level = atoi(getenv("CTFCONVERT_DEBUG_LEVEL"));
 161         if (getenv("CTFCONVERT_DEBUG_PARSE"))
 162                 debug_parse = atoi(getenv("CTFCONVERT_DEBUG_PARSE"));
 163 
 164         while ((c = getopt(argc, argv, ":l:L:o:ivs")) != EOF) {
 165                 switch (c) {
 166                 case 'l':
 167                         label = optarg;
 168                         break;
 169                 case 'L':
 170                         if ((label = getenv(optarg)) == NULL)
 171                                 label = CTF_DEFAULT_LABEL;
 172                         break;
 173                 case 'o':
 174                         outfile = optarg;
 175                         break;
 176                 case 's':
 177                         dynsym = CTF_USE_DYNSYM;
 178                         break;
 179                 case 'i':
 180                         ignore_non_c = 1;
 181                         break;



 182                 case 'v':
 183                         verbose = 1;
 184                         break;
 185                 default:
 186                         usage();
 187                         exit(2);
 188                 }
 189         }
 190 



 191         if (argc - optind != 1 || label == NULL) {
 192                 usage();
 193                 exit(2);
 194         }
 195 
 196         infile = argv[optind];
 197         if (access(infile, R_OK) != 0)
 198                 terminate("Can't access %s", infile);
 199 
 200         /*
 201          * Upon receipt of a signal, we want to clean up and exit.  Our
 202          * primary goal during cleanup is to restore the system to a state
 203          * such that a subsequent make will eventually cause this command to
 204          * be re-run.  If we remove the input file (which we do if we get a
 205          * signal and the user didn't specify a separate output file), make
 206          * will need to rebuild the input file, and will then need to re-run
 207          * ctfconvert, which is what we want.
 208          */
 209         set_terminate_cleanup(terminate_cleanup);
 210 


 214 
 215         filetd = tdata_new();
 216 
 217         if (!file_read(filetd, infile, ignore_non_c))
 218                 terminate("%s doesn't have type data to convert\n", infile);
 219 
 220         if (verbose)
 221                 iidesc_stats(filetd->td_iihash);
 222 
 223         mstrtd = tdata_new();
 224         merge_into_master(filetd, mstrtd, NULL, 1);
 225 
 226         tdata_label_add(mstrtd, label, CTF_LABEL_LASTIDX);
 227 
 228         /*
 229          * If the user supplied an output file that is different from the
 230          * input file, write directly to the output file.  Otherwise, write
 231          * to a temporary file, and replace the input file when we're done.
 232          */
 233         if (outfile && strcmp(infile, outfile) != 0) {
 234                 write_ctf(mstrtd, infile, outfile, dynsym);
 235         } else {
 236                 char *tmpname = mktmpname(infile, ".ctf");
 237 
 238                 write_ctf(mstrtd, infile, tmpname, dynsym);
 239                 if (rename(tmpname, infile) != 0)
 240                         terminate("Couldn't rename temp file %s", tmpname);
 241                 free(tmpname);
 242         }
 243 
 244         return (0);
 245 }