Print this page
5595 libzpool won't build with a studio primary
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/ctf/cvt/ctfconvert.c
+++ new/usr/src/tools/ctf/cvt/ctfconvert.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 26 /*
29 27 * Given a file containing sections with stabs data, convert the stabs data to
30 28 * CTF data, and replace the stabs sections with a CTF section.
31 29 */
32 30
33 31 #include <stdio.h>
34 32 #include <stdlib.h>
35 33 #include <unistd.h>
36 34 #include <signal.h>
37 35 #include <string.h>
38 36 #include <fcntl.h>
39 37 #include <libgen.h>
40 38 #include <errno.h>
41 39 #include <assert.h>
42 40
43 41 #include "ctftools.h"
44 42 #include "memory.h"
45 43
46 44 const char *progname;
47 45 int debug_level = DEBUG_LEVEL;
48 46
49 47 static const char *infile = NULL;
50 48 static const char *outfile = NULL;
51 49 static int dynsym;
52 50
53 51 static void
54 52 usage(void)
55 53 {
56 54 (void) fprintf(stderr,
57 55 "Usage: %s [-gis] -l label | -L labelenv [-o outfile] object_file\n"
58 56 "\n"
59 57 " Note: if -L labelenv is specified and labelenv is not set in\n"
60 58 " the environment, a default value is used.\n",
61 59 progname);
62 60 }
63 61
64 62 static void
65 63 terminate_cleanup(void)
66 64 {
67 65 if (!outfile) {
68 66 fprintf(stderr, "Removing %s\n", infile);
69 67 unlink(infile);
70 68 }
71 69 }
72 70
73 71 static void
74 72 handle_sig(int sig)
75 73 {
76 74 terminate("Caught signal %d - exiting\n", sig);
77 75 }
78 76
79 77 static int
80 78 file_read(tdata_t *td, const char *filename, int ignore_non_c)
81 79 {
82 80 typedef int (*reader_f)(tdata_t *, Elf *, const char *);
83 81 static const reader_f readers[] = {
84 82 stabs_read,
85 83 dw_read,
86 84 NULL
87 85 };
88 86
89 87 source_types_t source_types;
90 88 Elf *elf;
91 89 int i, rc, fd;
92 90
93 91 if ((fd = open(filename, O_RDONLY)) < 0)
94 92 terminate("failed to open %s", filename);
95 93
96 94 (void) elf_version(EV_CURRENT);
97 95
98 96 if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
99 97 close(fd);
100 98 terminate("failed to read %s: %s\n", filename,
101 99 elf_errmsg(-1));
102 100 }
103 101
104 102 source_types = built_source_types(elf, filename);
105 103
106 104 if ((source_types == SOURCE_NONE || (source_types & SOURCE_UNKNOWN)) &&
107 105 ignore_non_c) {
108 106 debug(1, "Ignoring file %s from unknown sources\n", filename);
109 107 exit(0);
110 108 }
111 109
112 110 for (i = 0; readers[i] != NULL; i++) {
113 111 if ((rc = readers[i](td, elf, filename)) == 0)
114 112 break;
115 113
116 114 assert(rc < 0 && errno == ENOENT);
117 115 }
118 116
119 117 if (readers[i] == NULL) {
120 118 /*
121 119 * None of the readers found compatible type data.
122 120 */
123 121
124 122 if (findelfsecidx(elf, filename, ".debug") >= 0) {
125 123 terminate("%s: DWARF version 1 is not supported\n",
126 124 filename);
127 125 }
128 126
129 127 if (!(source_types & SOURCE_C) && ignore_non_c) {
130 128 debug(1, "Ignoring file %s not built from C sources\n",
131 129 filename);
132 130 exit(0);
133 131 }
134 132
135 133 rc = 0;
136 134 } else {
137 135 rc = 1;
138 136 }
139 137
140 138 (void) elf_end(elf);
141 139 (void) close(fd);
142 140
↓ open down ↓ |
105 lines elided |
↑ open up ↑ |
143 141 return (rc);
144 142 }
145 143
146 144 int
147 145 main(int argc, char **argv)
148 146 {
149 147 tdata_t *filetd, *mstrtd;
150 148 char *label = NULL;
151 149 int verbose = 0;
152 150 int ignore_non_c = 0;
153 - int keep_stabs = 0;
154 151 int c;
155 152
156 153 sighold(SIGINT);
157 154 sighold(SIGQUIT);
158 155 sighold(SIGTERM);
159 156
160 157 progname = basename(argv[0]);
161 158
162 159 if (getenv("CTFCONVERT_DEBUG_LEVEL"))
163 160 debug_level = atoi(getenv("CTFCONVERT_DEBUG_LEVEL"));
164 161 if (getenv("CTFCONVERT_DEBUG_PARSE"))
165 162 debug_parse = atoi(getenv("CTFCONVERT_DEBUG_PARSE"));
166 163
167 - while ((c = getopt(argc, argv, ":l:L:o:givs")) != EOF) {
164 + while ((c = getopt(argc, argv, ":l:L:o:ivs")) != EOF) {
168 165 switch (c) {
169 166 case 'l':
170 167 label = optarg;
171 168 break;
172 169 case 'L':
173 170 if ((label = getenv(optarg)) == NULL)
174 171 label = CTF_DEFAULT_LABEL;
175 172 break;
176 173 case 'o':
177 174 outfile = optarg;
178 175 break;
179 176 case 's':
180 177 dynsym = CTF_USE_DYNSYM;
181 178 break;
182 179 case 'i':
183 180 ignore_non_c = 1;
184 181 break;
185 - case 'g':
186 - keep_stabs = CTF_KEEP_STABS;
187 - break;
188 182 case 'v':
189 183 verbose = 1;
190 184 break;
191 185 default:
192 186 usage();
193 187 exit(2);
194 188 }
195 189 }
196 190
197 - if (getenv("STRIPSTABS_KEEP_STABS") != NULL)
198 - keep_stabs = CTF_KEEP_STABS;
199 -
200 191 if (argc - optind != 1 || label == NULL) {
201 192 usage();
202 193 exit(2);
203 194 }
204 195
205 196 infile = argv[optind];
206 197 if (access(infile, R_OK) != 0)
207 198 terminate("Can't access %s", infile);
208 199
209 200 /*
210 201 * Upon receipt of a signal, we want to clean up and exit. Our
211 202 * primary goal during cleanup is to restore the system to a state
212 203 * such that a subsequent make will eventually cause this command to
213 204 * be re-run. If we remove the input file (which we do if we get a
214 205 * signal and the user didn't specify a separate output file), make
215 206 * will need to rebuild the input file, and will then need to re-run
216 207 * ctfconvert, which is what we want.
217 208 */
218 209 set_terminate_cleanup(terminate_cleanup);
219 210
220 211 sigset(SIGINT, handle_sig);
221 212 sigset(SIGQUIT, handle_sig);
222 213 sigset(SIGTERM, handle_sig);
223 214
224 215 filetd = tdata_new();
225 216
226 217 if (!file_read(filetd, infile, ignore_non_c))
227 218 terminate("%s doesn't have type data to convert\n", infile);
228 219
229 220 if (verbose)
230 221 iidesc_stats(filetd->td_iihash);
231 222
232 223 mstrtd = tdata_new();
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
233 224 merge_into_master(filetd, mstrtd, NULL, 1);
234 225
235 226 tdata_label_add(mstrtd, label, CTF_LABEL_LASTIDX);
236 227
237 228 /*
238 229 * If the user supplied an output file that is different from the
239 230 * input file, write directly to the output file. Otherwise, write
240 231 * to a temporary file, and replace the input file when we're done.
241 232 */
242 233 if (outfile && strcmp(infile, outfile) != 0) {
243 - write_ctf(mstrtd, infile, outfile, dynsym | keep_stabs);
234 + write_ctf(mstrtd, infile, outfile, dynsym);
244 235 } else {
245 236 char *tmpname = mktmpname(infile, ".ctf");
246 237
247 - write_ctf(mstrtd, infile, tmpname, dynsym | keep_stabs);
238 + write_ctf(mstrtd, infile, tmpname, dynsym);
248 239 if (rename(tmpname, infile) != 0)
249 240 terminate("Couldn't rename temp file %s", tmpname);
250 241 free(tmpname);
251 242 }
252 243
253 244 return (0);
254 245 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX