Print this page
Cleanup temp files without rm
Cleanup cw tempfiles properly
Revert "Revert most of "9899 cw(1onbld) should shadow more compilation""
This reverts commit 67deef8cbc83060db238a0f4ee252d1ba74641ef.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/cw/cw.c
+++ new/usr/src/tools/cw/cw.c
1 1
2 2 /*
3 3 * CDDL HEADER START
4 4 *
5 5 * The contents of this file are subject to the terms of the
6 6 * Common Development and Distribution License (the "License").
7 7 * You may not use this file except in compliance with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22
23 23 /*
24 24 * Copyright 2018, Richard Lowe.
25 25 */
26 26 /*
27 27 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 29 */
30 30
31 31 /*
32 32 * Wrapper for the GNU C compiler to make it accept the Sun C compiler
33 33 * arguments where possible.
34 34 *
35 35 * Since the translation is inexact, this is something of a work-in-progress.
36 36 *
37 37 */
38 38
39 39 /* If you modify this file, you must increment CW_VERSION */
40 40 #define CW_VERSION "3.0"
41 41
42 42 /*
43 43 * -# Verbose mode
44 44 * -### Show compiler commands built by driver, no compilation
45 45 * -A<name[(tokens)]> Preprocessor predicate assertion
46 46 * -B<[static|dynamic]> Specify dynamic or static binding
47 47 * -C Prevent preprocessor from removing comments
48 48 * -c Compile only - produce .o files, suppress linking
49 49 * -cg92 Alias for -xtarget=ss1000
50 50 * -D<name[=token]> Associate name with token as if by #define
51 51 * -d[y|n] dynamic [-dy] or static [-dn] option to linker
52 52 * -E Compile source through preprocessor only, output to stdout
53 53 * -erroff=<t> Suppress warnings specified by tags t(%none, %all, <tag list>)
54 54 * -errtags=<a> Display messages with tags a(no, yes)
55 55 * -errwarn=<t> Treats warnings specified by tags t(%none, %all, <tag list>)
56 56 * as errors
57 57 * -fast Optimize using a selection of options
58 58 * -fd Report old-style function definitions and declarations
59 59 * -fnonstd Initialize floating-point hardware to non-standard preferences
60 60 * -fns[=<yes|no>] Select non-standard floating point mode
61 61 * -fprecision=<p> Set FP rounding precision mode p(single, double, extended)
62 62 * -fround=<r> Select the IEEE rounding mode in effect at startup
63 63 * -fsimple[=<n>] Select floating-point optimization preferences <n>
64 64 * -fsingle Use single-precision arithmetic (-Xt and -Xs modes only)
65 65 * -ftrap=<t> Select floating-point trapping mode in effect at startup
66 66 * -fstore force floating pt. values to target precision on assignment
67 67 * -G Build a dynamic shared library
68 68 * -g Compile for debugging
69 69 * -H Print path name of each file included during compilation
70 70 * -h <name> Assign <name> to generated dynamic shared library
71 71 * -I<dir> Add <dir> to preprocessor #include file search path
72 72 * -i Passed to linker to ignore any LD_LIBRARY_PATH setting
73 73 * -keeptmp Keep temporary files created during compilation
74 74 * -L<dir> Pass to linker to add <dir> to the library search path
75 75 * -l<name> Link with library lib<name>.a or lib<name>.so
76 76 * -mc Remove duplicate strings from .comment section of output files
77 77 * -mr Remove all strings from .comment section of output files
78 78 * -mr,"string" Remove all strings and append "string" to .comment section
79 79 * -mt Specify options needed when compiling multi-threaded code
80 80 * -native Find available processor, generate code accordingly
81 81 * -nofstore Do not force floating pt. values to target precision
82 82 * on assignment
83 83 * -norunpath Do not build in a runtime path for shared libraries
84 84 * -O Use default optimization level (-xO2 or -xO3. Check man page.)
85 85 * -o <outputfile> Set name of output file to <outputfile>
86 86 * -P Compile source through preprocessor only, output to .i file
87 87 * -p Compile for profiling with prof
88 88 * -Q[y|n] Emit/don't emit identification info to output file
89 89 * -R<dir[:dir]> Build runtime search path list into executable
90 90 * -S Compile and only generate assembly code (.s)
91 91 * -s Strip symbol table from the executable file
92 92 * -t Turn off duplicate symbol warnings when linking
93 93 * -U<name> Delete initial definition of preprocessor symbol <name>
94 94 * -V Report version number of each compilation phase
95 95 * -v Do stricter semantic checking
96 96 * -W<c>,<arg> Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
97 97 * -w Suppress compiler warning messages
98 98 * -Xa Compile assuming ANSI C conformance, allow K & R extensions
99 99 * (default mode)
100 100 * -Xs Compile assuming (pre-ANSI) K & R C style code
101 101 * -Xt Compile assuming K & R conformance, allow ANSI C
102 102 * -xarch=<a> Specify target architecture instruction set
103 103 * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
104 104 * for system functions, b={%all,%none}
105 105 * -xCC Accept C++ style comments
106 106 * -xchip=<c> Specify the target processor for use by the optimizer
107 107 * -xcode=<c> Generate different code for forming addresses
108 108 * -xcrossfile[=<n>] Enable optimization and inlining across source files,
109 109 * n={0|1}
110 110 * -xe Perform only syntax/semantic checking, no code generation
111 111 * -xF Compile for later mapfile reordering or unused section
112 112 * elimination
113 113 * -xhelp=<f> Display on-line help information f(flags, readme, errors)
114 114 * -xildoff Cancel -xildon
115 115 * -xildon Enable use of the incremental linker, ild
116 116 * -xinline=[<a>,...,<a>] Attempt inlining of specified user routines,
117 117 * <a>={%auto,func,no%func}
118 118 * -xlibmieee Force IEEE 754 return values for math routines in
119 119 * exceptional cases
120 120 * -xlibmil Inline selected libm math routines for optimization
121 121 * -xlic_lib=sunperf Link in the Sun supplied performance libraries
122 122 * -xlicinfo Show license server information
123 123 * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
124 124 * -xO<n> Generate optimized code (n={1|2|3|4|5})
125 125 * -xP Print prototypes for function definitions
126 126 * -xprofile=<p> Collect data for a profile or use a profile to optimize
127 127 * <p>={{collect,use}[:<path>],tcov}
128 128 * -xregs=<r> Control register allocation
129 129 * -xs Allow debugging without object (.o) files
130 130 * -xsb Compile for use with the WorkShop source browser
131 131 * -xsbfast Generate only WorkShop source browser info, no compilation
132 132 * -xsfpconst Represent unsuffixed floating point constants as single
133 133 * precision
134 134 * -xspace Do not do optimizations that increase code size
135 135 * -xstrconst Place string literals into read-only data segment
136 136 * -xtarget=<t> Specify target system for optimization
137 137 * -xtemp=<dir> Set directory for temporary files to <dir>
138 138 * -xtime Report the execution time for each compilation phase
139 139 * -xunroll=n Enable unrolling loops n times where possible
140 140 * -Y<c>,<dir> Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
141 141 * -YA,<dir> Change default directory searched for components
142 142 * -YI,<dir> Change default directory searched for include files
143 143 * -YP,<dir> Change default directory for finding libraries files
144 144 * -YS,<dir> Change default directory for startup object files
145 145 */
146 146
147 147 /*
148 148 * Translation table:
149 149 */
150 150 /*
151 151 * -# -v
152 152 * -### error
153 153 * -A<name[(tokens)]> pass-thru
154 154 * -B<[static|dynamic]> pass-thru (syntax error for anything else)
155 155 * -C pass-thru
156 156 * -c pass-thru
157 157 * -cg92 -m32 -mcpu=v8 -mtune=supersparc (SPARC only)
158 158 * -D<name[=token]> pass-thru
159 159 * -dy or -dn -Wl,-dy or -Wl,-dn
160 160 * -E pass-thru
161 161 * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
162 162 * -errtags=%all -Wall
163 163 * -errwarn=%all -Werror else -Wno-error
164 164 * -fast error
165 165 * -fd error
166 166 * -fnonstd error
167 167 * -fns[=<yes|no>] error
168 168 * -fprecision=<p> error
169 169 * -fround=<r> error
170 170 * -fsimple[=<n>] error
171 171 * -fsingle[=<n>] error
172 172 * -ftrap=<t> error
173 173 * -fstore error
174 174 * -G pass-thru
175 175 * -g pass-thru
176 176 * -H pass-thru
177 177 * -h <name> pass-thru
178 178 * -I<dir> pass-thru
179 179 * -i pass-thru
180 180 * -keeptmp -save-temps
181 181 * -L<dir> pass-thru
182 182 * -l<name> pass-thru
183 183 * -mc error
184 184 * -mr error
185 185 * -mr,"string" error
186 186 * -mt -D_REENTRANT
187 187 * -native error
188 188 * -nofstore error
189 189 * -nolib -nodefaultlibs
190 190 * -norunpath ignore
191 191 * -O -O1 (Check the man page to be certain)
192 192 * -o <outputfile> pass-thru
193 193 * -P -E -o filename.i (or error)
194 194 * -p pass-thru
195 195 * -Q[y|n] error
196 196 * -R<dir[:dir]> pass-thru
197 197 * -S pass-thru
198 198 * -s -Wl,-s
199 199 * -t -Wl,-t
200 200 * -U<name> pass-thru
201 201 * -V --version
202 202 * -v -Wall
203 203 * -Wa,<arg> pass-thru
204 204 * -Wp,<arg> pass-thru except -xc99=<a>
205 205 * -Wl,<arg> pass-thru
206 206 * -W{m,0,2,h,i,u> error/ignore
207 207 * -xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone
208 208 * -Wu,-save_args -msave-args
209 209 * -w pass-thru
210 210 * -Xa -std=iso9899:199409 or -ansi
211 211 * -Xt error
212 212 * -Xs -traditional -std=c89
213 213 * -xarch=<a> table
214 214 * -xbuiltin[=<b>] -fbuiltin (-fno-builtin otherwise)
215 215 * -xCC ignore
216 216 * -xchip=<c> table
217 217 * -xcode=<c> table
218 218 * -xdebugformat=<format> ignore (always use dwarf-2 for gcc)
219 219 * -xcrossfile[=<n>] ignore
220 220 * -xe error
221 221 * -xF error
222 222 * -xhelp=<f> error
223 223 * -xildoff ignore
224 224 * -xildon ignore
225 225 * -xinline ignore
226 226 * -xlibmieee error
227 227 * -xlibmil error
228 228 * -xlic_lib=sunperf error
229 229 * -xmaxopt=[...] error
230 230 * -xO<n> -O<n>
231 231 * -xP error
232 232 * -xprofile=<p> error
233 233 * -xregs=<r> table
234 234 * -xs error
235 235 * -xsb error
236 236 * -xsbfast error
237 237 * -xsfpconst error
238 238 * -xspace ignore (-not -Os)
239 239 * -xstrconst ignore
240 240 * -xtarget=<t> table
241 241 * -xtemp=<dir> error
242 242 * -xtime error
243 243 * -xtransition -Wtransition
244 244 * -xunroll=n error
245 245 * -W0,-xdbggen=no%usedonly -fno-eliminate-unused-debug-symbols
246 246 * -fno-eliminate-unused-debug-types
247 247 * -Y<c>,<dir> error
248 248 * -YA,<dir> error
249 249 * -YI,<dir> -nostdinc -I<dir>
250 250 * -YP,<dir> error
251 251 * -YS,<dir> error
252 252 */
↓ open down ↓ |
252 lines elided |
↑ open up ↑ |
253 253
254 254 #include <ctype.h>
255 255 #include <err.h>
256 256 #include <errno.h>
257 257 #include <fcntl.h>
258 258 #include <getopt.h>
259 259 #include <stdio.h>
260 260 #include <stdlib.h>
261 261 #include <string.h>
262 262 #include <unistd.h>
263 +#include <dirent.h>
263 264
264 265 #include <sys/param.h>
265 266 #include <sys/stat.h>
266 267 #include <sys/types.h>
267 268 #include <sys/utsname.h>
268 269 #include <sys/wait.h>
269 270
270 271 #define CW_F_CXX 0x01
271 272 #define CW_F_SHADOW 0x02
272 273 #define CW_F_EXEC 0x04
273 274 #define CW_F_ECHO 0x08
274 275 #define CW_F_XLATE 0x10
275 276 #define CW_F_PROG 0x20
276 277
277 278 typedef enum cw_op {
278 279 CW_O_NONE = 0,
279 280 CW_O_PREPROCESS,
280 281 CW_O_COMPILE,
281 282 CW_O_LINK
282 283 } cw_op_t;
283 284
284 285 struct aelist {
285 286 struct ae {
286 287 struct ae *ae_next;
287 288 char *ae_arg;
288 289 } *ael_head, *ael_tail;
289 290 int ael_argc;
290 291 };
291 292
292 293 typedef enum {
293 294 GNU,
294 295 SUN
295 296 } compiler_style_t;
296 297
297 298 typedef struct {
298 299 char *c_name;
299 300 char *c_path;
300 301 compiler_style_t c_style;
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
301 302 } cw_compiler_t;
302 303
303 304 typedef struct cw_ictx {
304 305 struct cw_ictx *i_next;
305 306 cw_compiler_t *i_compiler;
306 307 struct aelist *i_ae;
307 308 uint32_t i_flags;
308 309 int i_oldargc;
309 310 char **i_oldargv;
310 311 pid_t i_pid;
311 - char i_discard[MAXPATHLEN];
312 + char *i_tmpdir;
312 313 char *i_stderr;
313 314 } cw_ictx_t;
314 315
315 316 /*
316 317 * Status values to indicate which Studio compiler and associated
317 318 * flags are being used.
318 319 */
319 320 #define M32 0x01 /* -m32 - only on Studio 12 */
320 321 #define M64 0x02 /* -m64 - only on Studio 12 */
321 322 #define SS11 0x100 /* Studio 11 */
322 323 #define SS12 0x200 /* Studio 12 */
323 324
324 325 #define TRANS_ENTRY 5
325 326 /*
326 327 * Translation table definition for the -xarch= flag. The "x_arg"
327 328 * value is translated into the appropriate gcc flags according
328 329 * to the values in x_trans[n]. The x_flags indicates what compiler
329 330 * is being used and what flags have been set via the use of
330 331 * "x_arg".
331 332 */
332 333 typedef struct xarch_table {
333 334 char *x_arg;
334 335 int x_flags;
335 336 char *x_trans[TRANS_ENTRY];
336 337 } xarch_table_t;
337 338
338 339 /*
339 340 * The translation table for the -xarch= flag used in the Studio compilers.
340 341 */
341 342 static const xarch_table_t xtbl[] = {
342 343 #if defined(__x86)
343 344 { "generic", SS11, {NULL} },
344 345 { "generic64", (SS11|M64), { "-m64", "-mtune=opteron" } },
345 346 { "amd64", (SS11|M64), { "-m64", "-mtune=opteron" } },
346 347 { "386", SS11, { "-march=i386" } },
347 348 { "pentium_pro", SS11, { "-march=pentiumpro" } },
348 349 { "sse", SS11, { "-msse", "-mfpmath=sse" } },
349 350 { "sse2", SS11, { "-msse2", "-mfpmath=sse" } },
350 351 #elif defined(__sparc)
351 352 { "generic", (SS11|M32), { "-m32", "-mcpu=v8" } },
352 353 { "generic64", (SS11|M64), { "-m64", "-mcpu=v9" } },
353 354 { "v8", (SS11|M32), { "-m32", "-mcpu=v8", "-mno-v8plus" } },
354 355 { "v8plus", (SS11|M32), { "-m32", "-mcpu=v9", "-mv8plus" } },
355 356 { "v8plusa", (SS11|M32), { "-m32", "-mcpu=ultrasparc", "-mv8plus",
356 357 "-mvis" } },
357 358 { "v8plusb", (SS11|M32), { "-m32", "-mcpu=ultrasparc3", "-mv8plus",
358 359 "-mvis" } },
359 360 { "v9", (SS11|M64), { "-m64", "-mcpu=v9" } },
360 361 { "v9a", (SS11|M64), { "-m64", "-mcpu=ultrasparc", "-mvis" } },
361 362 { "v9b", (SS11|M64), { "-m64", "-mcpu=ultrasparc3", "-mvis" } },
362 363 { "sparc", SS12, { "-mcpu=v9", "-mv8plus" } },
363 364 { "sparcvis", SS12, { "-mcpu=ultrasparc", "-mvis" } },
364 365 { "sparcvis2", SS12, { "-mcpu=ultrasparc3", "-mvis" } }
365 366 #endif
366 367 };
367 368
368 369 static int xtbl_size = sizeof (xtbl) / sizeof (xarch_table_t);
369 370
370 371 static const char *xchip_tbl[] = {
371 372 #if defined(__x86)
372 373 "386", "-mtune=i386", NULL,
373 374 "486", "-mtune=i486", NULL,
374 375 "pentium", "-mtune=pentium", NULL,
375 376 "pentium_pro", "-mtune=pentiumpro", NULL,
376 377 #elif defined(__sparc)
377 378 "super", "-mtune=supersparc", NULL,
378 379 "ultra", "-mtune=ultrasparc", NULL,
379 380 "ultra3", "-mtune=ultrasparc3", NULL,
380 381 #endif
381 382 NULL, NULL
382 383 };
383 384
384 385 static const char *xcode_tbl[] = {
385 386 #if defined(__sparc)
386 387 "abs32", "-fno-pic", "-mcmodel=medlow", NULL,
387 388 "abs44", "-fno-pic", "-mcmodel=medmid", NULL,
388 389 "abs64", "-fno-pic", "-mcmodel=medany", NULL,
389 390 "pic13", "-fpic", NULL,
390 391 "pic32", "-fPIC", NULL,
391 392 #endif
392 393 NULL, NULL
393 394 };
394 395
395 396 static const char *xtarget_tbl[] = {
396 397 #if defined(__x86)
397 398 "pentium_pro", "-march=pentiumpro", NULL,
398 399 #endif /* __x86 */
399 400 NULL, NULL
400 401 };
401 402
402 403 static const char *xregs_tbl[] = {
403 404 #if defined(__sparc)
404 405 "appl", "-mapp-regs", NULL,
405 406 "no%appl", "-mno-app-regs", NULL,
406 407 "float", "-mfpu", NULL,
407 408 "no%float", "-mno-fpu", NULL,
408 409 #endif /* __sparc */
409 410 NULL, NULL
410 411 };
411 412
412 413 static void
413 414 nomem(void)
414 415 {
415 416 errx(1, "out of memory");
416 417 }
417 418
418 419 static void
419 420 newae(struct aelist *ael, const char *arg)
420 421 {
421 422 struct ae *ae;
422 423
423 424 if ((ae = calloc(sizeof (*ae), 1)) == NULL)
424 425 nomem();
425 426 ae->ae_arg = strdup(arg);
426 427 if (ael->ael_tail == NULL)
427 428 ael->ael_head = ae;
428 429 else
429 430 ael->ael_tail->ae_next = ae;
430 431 ael->ael_tail = ae;
431 432 ael->ael_argc++;
432 433 }
433 434
434 435 static cw_ictx_t *
435 436 newictx(void)
436 437 {
437 438 cw_ictx_t *ctx = calloc(sizeof (cw_ictx_t), 1);
438 439 if (ctx)
439 440 if ((ctx->i_ae = calloc(sizeof (struct aelist), 1)) == NULL) {
440 441 free(ctx);
441 442 return (NULL);
442 443 }
443 444
444 445 return (ctx);
445 446 }
446 447
447 448 static void
448 449 error(const char *arg)
449 450 {
450 451 errx(2, "error: mapping failed at or near arg '%s'", arg);
451 452 }
452 453
453 454 /*
454 455 * Add the current favourite set of warnings to the gcc invocation.
455 456 */
456 457 static void
457 458 warnings(struct aelist *h)
458 459 {
459 460 static int warningsonce;
460 461
461 462 if (warningsonce++)
462 463 return;
463 464
464 465 /*
465 466 * Enable as many warnings as exist, then disable those that we never
466 467 * ever want.
467 468 */
468 469 newae(h, "-Wall");
469 470 newae(h, "-Wextra");
470 471 }
471 472
472 473 static void
473 474 optim_disable(struct aelist *h, int level)
474 475 {
475 476 if (level >= 2) {
476 477 newae(h, "-fno-strict-aliasing");
477 478 newae(h, "-fno-unit-at-a-time");
478 479 newae(h, "-fno-optimize-sibling-calls");
479 480 }
480 481 }
481 482
482 483 static void
483 484 Xsmode(struct aelist *h)
484 485 {
485 486 static int xsonce;
486 487
487 488 if (xsonce++)
488 489 return;
489 490
490 491 newae(h, "-traditional");
491 492 newae(h, "-traditional-cpp");
492 493 }
493 494
494 495 static void
495 496 usage()
496 497 {
497 498 extern char *__progname;
498 499 (void) fprintf(stderr,
499 500 "usage: %s [-C] [--versions] --primary <compiler> "
500 501 "[--shadow <compiler>]... -- cflags...\n",
501 502 __progname);
502 503 (void) fprintf(stderr, "compilers take the form: name,path,style\n"
503 504 " - name: a unique name usable in flag specifiers\n"
504 505 " - path: path to the compiler binary\n"
505 506 " - style: the style of flags expected: either sun or gnu\n");
506 507 exit(2);
507 508 }
508 509
509 510 static int
510 511 xlate_xtb(struct aelist *h, const char *xarg)
511 512 {
512 513 int i, j;
513 514
514 515 for (i = 0; i < xtbl_size; i++) {
515 516 if (strcmp(xtbl[i].x_arg, xarg) == 0)
516 517 break;
517 518 }
518 519
519 520 /*
520 521 * At the end of the table and so no matching "arg" entry
521 522 * found and so this must be a bad -xarch= flag.
522 523 */
523 524 if (i == xtbl_size)
524 525 error(xarg);
525 526
526 527 for (j = 0; j < TRANS_ENTRY; j++) {
527 528 if (xtbl[i].x_trans[j] != NULL)
528 529 newae(h, xtbl[i].x_trans[j]);
529 530 else
530 531 break;
531 532 }
532 533 return (xtbl[i].x_flags);
533 534
534 535 }
535 536
536 537 static void
537 538 xlate(struct aelist *h, const char *xarg, const char **table)
538 539 {
539 540 while (*table != NULL && strcmp(xarg, *table) != 0) {
540 541 while (*table != NULL)
541 542 table++;
542 543 table++;
543 544 }
544 545
545 546 if (*table == NULL)
↓ open down ↓ |
224 lines elided |
↑ open up ↑ |
546 547 error(xarg);
547 548
548 549 table++;
549 550
550 551 while (*table != NULL) {
551 552 newae(h, *table);
552 553 table++;
553 554 }
554 555 }
555 556
557 +/*
558 + * The compiler wants the output file to end in appropriate extension. If
559 + * we're generating a name from whole cloth (path == NULL), we assume that
560 + * extension to be .o, otherwise we match the extension of the caller.
561 + */
562 +static char *
563 +discard_file_name(cw_ictx_t *ctx, const char *path)
564 +{
565 + char *ret, *ext;
566 + char tmpl[] = "cwXXXXXX";
567 +
568 + if (path == NULL) {
569 + ext = ".o";
570 + } else {
571 + ext = strrchr(path, '.');
572 + }
573 +
574 + /*
575 + * We need absolute control over where the temporary file goes, since
576 + * we rely on it for cleanup so tempnam(3C) and tmpnam(3C) are
577 + * inappropriate (they use TMPDIR, preferentially).
578 + *
579 + * mkstemp(3C) doesn't actually help us, since the temporary file
580 + * isn't used by us, only its name.
581 + */
582 + if (mktemp(tmpl) == NULL)
583 + nomem();
584 +
585 + (void) asprintf(&ret, "%s/%s%s", ctx->i_tmpdir, tmpl,
586 + (ext != NULL) ? ext : "");
587 +
588 + if (ret == NULL)
589 + nomem();
590 +
591 + return (ret);
592 +}
593 +
556 594 static void
557 595 do_gcc(cw_ictx_t *ctx)
558 596 {
559 597 int c;
560 598 int nolibc = 0;
561 599 int in_output = 0, seen_o = 0, c_files = 0;
562 600 cw_op_t op = CW_O_LINK;
563 601 char *model = NULL;
564 602 char *nameflag;
565 - int mflag = 0;
603 + int mflag = 0;
566 604
567 605 if (ctx->i_flags & CW_F_PROG) {
568 606 newae(ctx->i_ae, "--version");
569 607 return;
570 608 }
571 609
572 610 newae(ctx->i_ae, "-fident");
573 611 newae(ctx->i_ae, "-finline");
574 612 newae(ctx->i_ae, "-fno-inline-functions");
575 613 newae(ctx->i_ae, "-fno-builtin");
576 614 newae(ctx->i_ae, "-fno-asm");
577 615 newae(ctx->i_ae, "-fdiagnostics-show-option");
578 616 newae(ctx->i_ae, "-nodefaultlibs");
579 617
580 618 #if defined(__sparc)
581 619 /*
582 620 * The SPARC ldd and std instructions require 8-byte alignment of
583 621 * their address operand. gcc correctly uses them only when the
584 622 * ABI requires 8-byte alignment; unfortunately we have a number of
585 623 * pieces of buggy code that doesn't conform to the ABI. This
586 624 * flag makes gcc work more like Studio with -xmemalign=4.
587 625 */
588 626 newae(ctx->i_ae, "-mno-integer-ldd-std");
589 627 #endif
590 628
591 629 /*
592 630 * This is needed because 'u' is defined
593 631 * under a conditional on 'sun'. Should
594 632 * probably just remove the conditional,
595 633 * or make it be dependent on '__sun'.
596 634 *
597 635 * -Dunix is also missing in enhanced ANSI mode
598 636 */
599 637 newae(ctx->i_ae, "-D__sun");
600 638
601 639 if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1)
602 640 nomem();
603 641
604 642 /*
605 643 * Walk the argument list, translating as we go ..
606 644 */
607 645 while (--ctx->i_oldargc > 0) {
608 646 char *arg = *++ctx->i_oldargv;
609 647 size_t arglen = strlen(arg);
610 648
611 649 if (*arg == '-') {
612 650 arglen--;
613 651 } else {
614 652 /*
615 653 * Discard inline files that gcc doesn't grok
616 654 */
617 655 if (!in_output && arglen > 3 &&
618 656 strcmp(arg + arglen - 3, ".il") == 0)
619 657 continue;
620 658
621 659 if (!in_output && arglen > 2 &&
622 660 arg[arglen - 2] == '.' &&
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
623 661 (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
624 662 arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
625 663 c_files++;
626 664
627 665 /*
628 666 * Otherwise, filenames and partial arguments
629 667 * are passed through for gcc to chew on. However,
630 668 * output is always discarded for the secondary
631 669 * compiler.
632 670 */
633 - if ((ctx->i_flags & CW_F_SHADOW) && in_output)
634 - newae(ctx->i_ae, ctx->i_discard);
635 - else
671 + if ((ctx->i_flags & CW_F_SHADOW) && in_output) {
672 + newae(ctx->i_ae, discard_file_name(ctx, arg));
673 + } else {
636 674 newae(ctx->i_ae, arg);
675 + }
637 676 in_output = 0;
638 677 continue;
639 678 }
640 679
641 680 if (ctx->i_flags & CW_F_CXX) {
642 681 if (strncmp(arg, "-_g++=", 6) == 0) {
643 682 newae(ctx->i_ae, strchr(arg, '=') + 1);
644 683 continue;
645 684 }
646 685 if (strncmp(arg, "-compat=", 8) == 0) {
647 686 /* discard -compat=4 and -compat=5 */
648 687 continue;
649 688 }
650 689 if (strcmp(arg, "-Qoption") == 0) {
651 690 /* discard -Qoption and its two arguments */
652 691 if (ctx->i_oldargc < 3)
653 692 error(arg);
654 693 ctx->i_oldargc -= 2;
655 694 ctx->i_oldargv += 2;
656 695 continue;
657 696 }
658 697 if (strcmp(arg, "-xwe") == 0) {
659 698 /* turn warnings into errors */
660 699 newae(ctx->i_ae, "-Werror");
661 700 continue;
662 701 }
663 702 if (strcmp(arg, "-norunpath") == 0) {
664 703 /* gcc has no corresponding option */
665 704 continue;
666 705 }
667 706 if (strcmp(arg, "-nolib") == 0) {
668 707 /* -nodefaultlibs is on by default */
669 708 nolibc = 1;
670 709 continue;
671 710 }
672 711 #if defined(__sparc)
673 712 if (strcmp(arg, "-cg92") == 0) {
674 713 mflag |= xlate_xtb(ctx->i_ae, "v8");
675 714 xlate(ctx->i_ae, "super", xchip_tbl);
676 715 continue;
677 716 }
678 717 #endif /* __sparc */
679 718 }
680 719
681 720 switch ((c = arg[1])) {
682 721 case '_':
683 722 if ((strncmp(arg, nameflag, strlen(nameflag)) == 0) ||
684 723 (strncmp(arg, "-_gcc=", 6) == 0) ||
685 724 (strncmp(arg, "-_gnu=", 6) == 0)) {
686 725 newae(ctx->i_ae, strchr(arg, '=') + 1);
687 726 }
688 727 break;
689 728 case '#':
690 729 if (arglen == 1) {
691 730 newae(ctx->i_ae, "-v");
692 731 break;
693 732 }
694 733 error(arg);
695 734 break;
696 735 case 'f':
697 736 if ((strcmp(arg, "-fpic") == 0) ||
698 737 (strcmp(arg, "-fPIC") == 0)) {
699 738 newae(ctx->i_ae, arg);
700 739 break;
701 740 }
702 741 error(arg);
703 742 break;
704 743 case 'g':
705 744 newae(ctx->i_ae, "-gdwarf-2");
706 745 break;
707 746 case 'E':
708 747 if (arglen == 1) {
709 748 newae(ctx->i_ae, "-xc");
710 749 newae(ctx->i_ae, arg);
711 750 op = CW_O_PREPROCESS;
712 751 nolibc = 1;
713 752 break;
714 753 }
715 754 error(arg);
716 755 break;
717 756 case 'c':
718 757 case 'S':
719 758 if (arglen == 1) {
720 759 op = CW_O_COMPILE;
721 760 nolibc = 1;
722 761 }
723 762 /* FALLTHROUGH */
724 763 case 'C':
725 764 case 'H':
726 765 case 'p':
727 766 if (arglen == 1) {
728 767 newae(ctx->i_ae, arg);
729 768 break;
730 769 }
731 770 error(arg);
732 771 break;
733 772 case 'A':
734 773 case 'h':
735 774 case 'I':
736 775 case 'i':
737 776 case 'L':
738 777 case 'l':
739 778 case 'R':
740 779 case 'U':
741 780 case 'u':
↓ open down ↓ |
95 lines elided |
↑ open up ↑ |
742 781 case 'w':
743 782 newae(ctx->i_ae, arg);
744 783 break;
745 784 case 'o':
746 785 seen_o = 1;
747 786 if (arglen == 1) {
748 787 in_output = 1;
749 788 newae(ctx->i_ae, arg);
750 789 } else if (ctx->i_flags & CW_F_SHADOW) {
751 790 newae(ctx->i_ae, "-o");
752 - newae(ctx->i_ae, ctx->i_discard);
791 + newae(ctx->i_ae, discard_file_name(ctx, arg));
753 792 } else {
754 793 newae(ctx->i_ae, arg);
755 794 }
756 795 break;
757 796 case 'D':
758 797 newae(ctx->i_ae, arg);
759 798 /*
760 799 * XXX Clearly a hack ... do we need _KADB too?
761 800 */
762 801 if (strcmp(arg, "-D_KERNEL") == 0 ||
763 802 strcmp(arg, "-D_BOOT") == 0)
764 803 newae(ctx->i_ae, "-ffreestanding");
765 804 break;
766 805 case 'd':
767 806 if (arglen == 2) {
768 807 if (strcmp(arg, "-dy") == 0) {
769 808 newae(ctx->i_ae, "-Wl,-dy");
770 809 break;
771 810 }
772 811 if (strcmp(arg, "-dn") == 0) {
773 812 newae(ctx->i_ae, "-Wl,-dn");
774 813 break;
775 814 }
776 815 }
777 816 if (strcmp(arg, "-dalign") == 0) {
778 817 /*
779 818 * -dalign forces alignment in some cases;
780 819 * gcc does not need any flag to do this.
781 820 */
782 821 break;
783 822 }
784 823 error(arg);
785 824 break;
786 825 case 'e':
787 826 if (strcmp(arg,
788 827 "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) {
789 828 /*
790 829 * Accept but ignore this -- gcc doesn't
791 830 * seem to complain about empty translation
792 831 * units
793 832 */
794 833 break;
795 834 }
796 835 /* XX64 -- ignore all -erroff= options, for now */
797 836 if (strncmp(arg, "-erroff=", 8) == 0)
798 837 break;
799 838 if (strcmp(arg, "-errtags=yes") == 0) {
800 839 warnings(ctx->i_ae);
801 840 break;
802 841 }
803 842 if (strcmp(arg, "-errwarn=%all") == 0) {
804 843 newae(ctx->i_ae, "-Werror");
805 844 break;
806 845 }
807 846 error(arg);
808 847 break;
809 848 case 'G':
810 849 newae(ctx->i_ae, "-shared");
811 850 nolibc = 1;
812 851 break;
813 852 case 'k':
814 853 if (strcmp(arg, "-keeptmp") == 0) {
815 854 newae(ctx->i_ae, "-save-temps");
816 855 break;
817 856 }
818 857 error(arg);
819 858 break;
820 859 case 'm':
821 860 if (strcmp(arg, "-mt") == 0) {
822 861 newae(ctx->i_ae, "-D_REENTRANT");
823 862 break;
824 863 }
825 864 if (strcmp(arg, "-m64") == 0) {
826 865 newae(ctx->i_ae, "-m64");
827 866 #if defined(__x86)
828 867 newae(ctx->i_ae, "-mtune=opteron");
829 868 #endif
830 869 mflag |= M64;
831 870 break;
832 871 }
833 872 if (strcmp(arg, "-m32") == 0) {
834 873 newae(ctx->i_ae, "-m32");
835 874 mflag |= M32;
836 875 break;
837 876 }
838 877 error(arg);
839 878 break;
840 879 case 'B': /* linker options */
841 880 case 'M':
842 881 case 'z':
843 882 {
844 883 char *opt;
845 884 size_t len;
846 885 char *s;
847 886
848 887 if (arglen == 1) {
849 888 opt = *++ctx->i_oldargv;
850 889 if (opt == NULL || *opt == '\0')
851 890 error(arg);
852 891 ctx->i_oldargc--;
853 892 } else {
854 893 opt = arg + 2;
855 894 }
856 895 len = strlen(opt) + 7;
857 896 if ((s = malloc(len)) == NULL)
858 897 nomem();
859 898 (void) snprintf(s, len, "-Wl,-%c%s", c, opt);
860 899 newae(ctx->i_ae, s);
861 900 free(s);
862 901 }
863 902 break;
864 903 case 'O':
865 904 if (arglen == 1) {
866 905 newae(ctx->i_ae, "-O");
867 906 break;
868 907 }
869 908 error(arg);
870 909 break;
871 910 case 'P':
872 911 /*
873 912 * We could do '-E -o filename.i', but that's hard,
874 913 * and we don't need it for the case that's triggering
875 914 * this addition. We'll require the user to specify
876 915 * -o in the Makefile. If they don't they'll find out
877 916 * in a hurry.
878 917 */
879 918 newae(ctx->i_ae, "-E");
880 919 op = CW_O_PREPROCESS;
881 920 nolibc = 1;
882 921 break;
883 922 case 's':
884 923 if (arglen == 1) {
885 924 newae(ctx->i_ae, "-Wl,-s");
886 925 break;
887 926 }
888 927 error(arg);
889 928 break;
890 929 case 't':
891 930 if (arglen == 1) {
892 931 newae(ctx->i_ae, "-Wl,-t");
893 932 break;
894 933 }
895 934 error(arg);
896 935 break;
897 936 case 'V':
898 937 if (arglen == 1) {
899 938 ctx->i_flags &= ~CW_F_ECHO;
900 939 newae(ctx->i_ae, "--version");
901 940 break;
902 941 }
903 942 error(arg);
904 943 break;
905 944 case 'v':
906 945 if (arglen == 1) {
907 946 warnings(ctx->i_ae);
908 947 break;
909 948 }
910 949 error(arg);
911 950 break;
912 951 case 'W':
913 952 if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
914 953 /*
915 954 * gcc's preprocessor will accept c99
916 955 * regardless, so accept and ignore.
917 956 */
918 957 break;
919 958 }
920 959 if (strncmp(arg, "-Wa,", 4) == 0 ||
921 960 strncmp(arg, "-Wp,", 4) == 0 ||
922 961 strncmp(arg, "-Wl,", 4) == 0) {
923 962 newae(ctx->i_ae, arg);
924 963 break;
925 964 }
926 965 if (strcmp(arg, "-W0,-noglobal") == 0 ||
927 966 strcmp(arg, "-W0,-xglobalstatic") == 0) {
928 967 /*
929 968 * gcc doesn't prefix local symbols
930 969 * in debug mode, so this is not needed.
931 970 */
932 971 break;
933 972 }
934 973 if (strcmp(arg, "-W0,-Lt") == 0) {
935 974 /*
936 975 * Generate tests at the top of loops.
937 976 * There is no direct gcc equivalent, ignore.
938 977 */
939 978 break;
940 979 }
941 980 if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) {
942 981 newae(ctx->i_ae,
943 982 "-fno-eliminate-unused-debug-symbols");
944 983 newae(ctx->i_ae,
945 984 "-fno-eliminate-unused-debug-types");
946 985 break;
947 986 }
948 987 if (strcmp(arg, "-W2,-xwrap_int") == 0) {
949 988 /*
950 989 * Use the legacy behaviour (pre-SS11)
951 990 * for integer wrapping.
952 991 * gcc does not need this.
953 992 */
954 993 break;
955 994 }
956 995 if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
957 996 /*
958 997 * Prevents optimizing away checks for
959 998 * unbound weak symbol addresses. gcc does
960 999 * not do this, so it's not needed.
961 1000 */
962 1001 break;
963 1002 }
964 1003 if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
965 1004 xlate(ctx->i_ae, arg + 11, xcode_tbl);
966 1005 break;
967 1006 }
968 1007 if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
969 1008 /*
970 1009 * Prevents insertion of register symbols.
971 1010 * gcc doesn't do this, so ignore it.
972 1011 */
973 1012 break;
974 1013 }
975 1014 if (strcmp(arg, "-Wc,-Qassembler-ounrefsym=0") == 0) {
976 1015 /*
977 1016 * Prevents optimizing away of static variables.
978 1017 * gcc does not do this, so it's not needed.
979 1018 */
980 1019 break;
981 1020 }
982 1021 #if defined(__x86)
983 1022 if (strcmp(arg, "-Wu,-save_args") == 0) {
984 1023 newae(ctx->i_ae, "-msave-args");
985 1024 break;
986 1025 }
987 1026 #endif /* __x86 */
988 1027 error(arg);
989 1028 break;
990 1029 case 'X':
991 1030 if (strcmp(arg, "-Xa") == 0 ||
992 1031 strcmp(arg, "-Xt") == 0) {
993 1032 break;
994 1033 }
995 1034 if (strcmp(arg, "-Xs") == 0) {
996 1035 Xsmode(ctx->i_ae);
997 1036 break;
998 1037 }
999 1038 error(arg);
1000 1039 break;
1001 1040 case 'x':
1002 1041 if (arglen == 1)
1003 1042 error(arg);
1004 1043 switch (arg[2]) {
1005 1044 case 'a':
1006 1045 if (strncmp(arg, "-xarch=", 7) == 0) {
1007 1046 mflag |= xlate_xtb(ctx->i_ae, arg + 7);
1008 1047 break;
1009 1048 }
1010 1049 error(arg);
1011 1050 break;
1012 1051 case 'b':
1013 1052 if (strncmp(arg, "-xbuiltin=", 10) == 0) {
1014 1053 if (strcmp(arg + 10, "%all"))
1015 1054 newae(ctx->i_ae, "-fbuiltin");
1016 1055 break;
1017 1056 }
1018 1057 error(arg);
1019 1058 break;
1020 1059 case 'C':
1021 1060 /* Accept C++ style comments -- ignore */
1022 1061 if (strcmp(arg, "-xCC") == 0)
1023 1062 break;
1024 1063 error(arg);
1025 1064 break;
1026 1065 case 'c':
1027 1066 if (strncmp(arg, "-xc99=%all", 10) == 0) {
1028 1067 newae(ctx->i_ae, "-std=gnu99");
1029 1068 break;
1030 1069 }
1031 1070 if (strncmp(arg, "-xc99=%none", 11) == 0) {
1032 1071 newae(ctx->i_ae, "-std=gnu89");
1033 1072 break;
1034 1073 }
1035 1074 if (strncmp(arg, "-xchip=", 7) == 0) {
1036 1075 xlate(ctx->i_ae, arg + 7, xchip_tbl);
1037 1076 break;
1038 1077 }
1039 1078 if (strncmp(arg, "-xcode=", 7) == 0) {
1040 1079 xlate(ctx->i_ae, arg + 7, xcode_tbl);
1041 1080 break;
1042 1081 }
1043 1082 if (strncmp(arg, "-xcrossfile", 11) == 0)
1044 1083 break;
1045 1084 error(arg);
1046 1085 break;
1047 1086 case 'd':
1048 1087 if (strncmp(arg, "-xdebugformat=", 14) == 0)
1049 1088 break;
1050 1089 error(arg);
1051 1090 break;
1052 1091 case 'F':
1053 1092 /*
1054 1093 * Compile for mapfile reordering, or unused
1055 1094 * section elimination, syntax can be -xF or
1056 1095 * more complex, like -xF=%all -- ignore.
1057 1096 */
1058 1097 if (strncmp(arg, "-xF", 3) == 0)
1059 1098 break;
1060 1099 error(arg);
1061 1100 break;
1062 1101 case 'i':
1063 1102 if (strncmp(arg, "-xinline", 8) == 0)
1064 1103 /* No inlining; ignore */
1065 1104 break;
1066 1105 if (strcmp(arg, "-xildon") == 0 ||
1067 1106 strcmp(arg, "-xildoff") == 0)
1068 1107 /* No incremental linking; ignore */
1069 1108 break;
1070 1109 error(arg);
1071 1110 break;
1072 1111 #if defined(__x86)
1073 1112 case 'm':
1074 1113 if (strcmp(arg, "-xmodel=kernel") == 0) {
1075 1114 newae(ctx->i_ae, "-ffreestanding");
1076 1115 newae(ctx->i_ae, "-mno-red-zone");
1077 1116 model = "-mcmodel=kernel";
1078 1117 nolibc = 1;
1079 1118 break;
1080 1119 }
1081 1120 error(arg);
1082 1121 break;
1083 1122 #endif /* __x86 */
1084 1123 case 'O':
1085 1124 if (strncmp(arg, "-xO", 3) == 0) {
1086 1125 size_t len = strlen(arg);
1087 1126 char *s = NULL;
1088 1127 int c = *(arg + 3);
1089 1128 int level;
1090 1129
1091 1130 if (len != 4 || !isdigit(c))
1092 1131 error(arg);
1093 1132
1094 1133 level = atoi(arg + 3);
1095 1134 if (level > 5)
1096 1135 error(arg);
1097 1136 if (level >= 2) {
1098 1137 /*
1099 1138 * For gcc-3.4.x at -O2 we
1100 1139 * need to disable optimizations
1101 1140 * that break ON.
1102 1141 */
1103 1142 optim_disable(ctx->i_ae, level);
1104 1143 /*
1105 1144 * limit -xO3 to -O2 as well.
1106 1145 */
1107 1146 level = 2;
1108 1147 }
1109 1148 if (asprintf(&s, "-O%d", level) == -1)
1110 1149 nomem();
1111 1150 newae(ctx->i_ae, s);
1112 1151 free(s);
1113 1152 break;
1114 1153 }
1115 1154 error(arg);
1116 1155 break;
1117 1156 case 'r':
1118 1157 if (strncmp(arg, "-xregs=", 7) == 0) {
1119 1158 xlate(ctx->i_ae, arg + 7, xregs_tbl);
1120 1159 break;
1121 1160 }
1122 1161 error(arg);
1123 1162 break;
1124 1163 case 's':
1125 1164 if (strcmp(arg, "-xs") == 0 ||
1126 1165 strcmp(arg, "-xspace") == 0 ||
1127 1166 strcmp(arg, "-xstrconst") == 0)
1128 1167 break;
1129 1168 error(arg);
1130 1169 break;
1131 1170 case 't':
1132 1171 if (strncmp(arg, "-xtarget=", 9) == 0) {
1133 1172 xlate(ctx->i_ae, arg + 9, xtarget_tbl);
1134 1173 break;
1135 1174 }
1136 1175 error(arg);
1137 1176 break;
1138 1177 case 'e':
1139 1178 case 'h':
1140 1179 case 'l':
1141 1180 default:
1142 1181 error(arg);
1143 1182 break;
1144 1183 }
1145 1184 break;
1146 1185 case 'Y':
1147 1186 if (arglen == 1) {
1148 1187 if ((arg = *++ctx->i_oldargv) == NULL ||
1149 1188 *arg == '\0')
1150 1189 error("-Y");
1151 1190 ctx->i_oldargc--;
1152 1191 arglen = strlen(arg + 1);
1153 1192 } else {
1154 1193 arg += 2;
1155 1194 }
1156 1195 /* Just ignore -YS,... for now */
1157 1196 if (strncmp(arg, "S,", 2) == 0)
1158 1197 break;
1159 1198 if (strncmp(arg, "l,", 2) == 0) {
1160 1199 char *s = strdup(arg);
1161 1200 s[0] = '-';
1162 1201 s[1] = 'B';
1163 1202 newae(ctx->i_ae, s);
1164 1203 free(s);
1165 1204 break;
1166 1205 }
1167 1206 if (strncmp(arg, "I,", 2) == 0) {
1168 1207 char *s = strdup(arg);
1169 1208 s[0] = '-';
1170 1209 s[1] = 'I';
1171 1210 newae(ctx->i_ae, "-nostdinc");
1172 1211 newae(ctx->i_ae, s);
1173 1212 free(s);
1174 1213 break;
1175 1214 }
1176 1215 error(arg);
1177 1216 break;
1178 1217 case 'Q':
1179 1218 /*
↓ open down ↓ |
417 lines elided |
↑ open up ↑ |
1180 1219 * We could map -Qy into -Wl,-Qy etc.
1181 1220 */
1182 1221 default:
1183 1222 error(arg);
1184 1223 break;
1185 1224 }
1186 1225 }
1187 1226
1188 1227 free(nameflag);
1189 1228
1190 - if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) &&
1191 - op != CW_O_PREPROCESS) {
1229 + /*
1230 + * When compiling multiple source files in a single invocation some
1231 + * compilers output objects into the current directory with
1232 + * predictable and conventional names.
1233 + *
1234 + * We prevent any attempt to compile multiple files at once so that
1235 + * any such objects created by a shadow can't escape into a later
1236 + * link-edit.
1237 + */
1238 + if (c_files > 1 && op != CW_O_PREPROCESS) {
1192 1239 errx(2, "multiple source files are "
1193 1240 "allowed only with -E or -P");
1194 1241 }
1195 1242
1196 1243 /*
1197 1244 * Make sure that we do not have any unintended interactions between
1198 1245 * the xarch options passed in and the version of the Studio compiler
1199 1246 * used.
1200 1247 */
1201 1248 if ((mflag & (SS11|SS12)) == (SS11|SS12)) {
1202 1249 errx(2,
1203 1250 "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n");
1204 1251 }
1205 1252
1206 1253 switch (mflag) {
1207 1254 case 0:
1208 1255 /* FALLTHROUGH */
1209 1256 case M32:
1210 1257 #if defined(__sparc)
1211 1258 /*
1212 1259 * Only -m32 is defined and so put in the missing xarch
1213 1260 * translation.
1214 1261 */
1215 1262 newae(ctx->i_ae, "-mcpu=v8");
1216 1263 newae(ctx->i_ae, "-mno-v8plus");
1217 1264 #endif
1218 1265 break;
1219 1266 case M64:
1220 1267 #if defined(__sparc)
1221 1268 /*
1222 1269 * Only -m64 is defined and so put in the missing xarch
1223 1270 * translation.
1224 1271 */
1225 1272 newae(ctx->i_ae, "-mcpu=v9");
1226 1273 #endif
1227 1274 break;
1228 1275 case SS12:
1229 1276 #if defined(__sparc)
1230 1277 /* no -m32/-m64 flag used - this is an error for sparc builds */
1231 1278 (void) fprintf(stderr, "No -m32/-m64 flag defined\n");
1232 1279 exit(2);
1233 1280 #endif
1234 1281 break;
1235 1282 case SS11:
1236 1283 /* FALLTHROUGH */
1237 1284 case (SS11|M32):
1238 1285 case (SS11|M64):
1239 1286 break;
1240 1287 case (SS12|M32):
1241 1288 #if defined(__sparc)
1242 1289 /*
1243 1290 * Need to add in further 32 bit options because with SS12
1244 1291 * the xarch=sparcvis option can be applied to 32 or 64
1245 1292 * bit, and so the translatation table (xtbl) cannot handle
1246 1293 * that.
1247 1294 */
1248 1295 newae(ctx->i_ae, "-mv8plus");
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
1249 1296 #endif
1250 1297 break;
1251 1298 case (SS12|M64):
1252 1299 break;
1253 1300 default:
1254 1301 (void) fprintf(stderr,
1255 1302 "Incompatible -xarch= and/or -m32/-m64 options used.\n");
1256 1303 exit(2);
1257 1304 }
1258 1305
1259 - if ((op == CW_O_LINK || op == CW_O_PREPROCESS) &&
1260 - (ctx->i_flags & CW_F_SHADOW))
1261 - exit(0);
1306 + if (ctx->i_flags & CW_F_SHADOW) {
1307 + if (op == CW_O_PREPROCESS)
1308 + exit(0);
1309 + else if (op == CW_O_LINK && c_files == 0)
1310 + exit(0);
1311 + }
1262 1312
1263 1313 if (model != NULL)
1264 1314 newae(ctx->i_ae, model);
1265 1315 if (!nolibc)
1266 1316 newae(ctx->i_ae, "-lc");
1267 1317 if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1268 1318 newae(ctx->i_ae, "-o");
1269 - newae(ctx->i_ae, ctx->i_discard);
1319 + newae(ctx->i_ae, discard_file_name(ctx, NULL));
1270 1320 }
1271 1321 }
1272 1322
1273 1323 static void
1274 1324 do_cc(cw_ictx_t *ctx)
1275 1325 {
1276 - int in_output = 0, seen_o = 0;
1326 + int in_output = 0, seen_o = 0, c_files = 0;
1277 1327 cw_op_t op = CW_O_LINK;
1278 1328 char *nameflag;
1279 1329
1280 1330 if (ctx->i_flags & CW_F_PROG) {
1281 1331 newae(ctx->i_ae, "-V");
1282 1332 return;
1283 1333 }
1284 1334
1285 1335 if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1)
1286 1336 nomem();
1287 1337
1288 1338 while (--ctx->i_oldargc > 0) {
1289 1339 char *arg = *++ctx->i_oldargv;
1340 + size_t arglen = strlen(arg);
1290 1341
1291 1342 if (strncmp(arg, "-_CC=", 5) == 0) {
1292 1343 newae(ctx->i_ae, strchr(arg, '=') + 1);
1293 1344 continue;
1294 1345 }
1295 1346
1296 1347 if (*arg != '-') {
1348 + if (!in_output && arglen > 2 &&
1349 + arg[arglen - 2] == '.' &&
1350 + (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
1351 + arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
1352 + c_files++;
1353 +
1297 1354 if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) {
1298 1355 newae(ctx->i_ae, arg);
1299 1356 } else {
1300 1357 in_output = 0;
1301 - newae(ctx->i_ae, ctx->i_discard);
1358 + newae(ctx->i_ae, discard_file_name(ctx, arg));
1302 1359 }
1303 1360 continue;
1304 1361 }
1305 1362 switch (*(arg + 1)) {
1306 1363 case '_':
1307 1364 if ((strncmp(arg, nameflag, strlen(nameflag)) == 0) ||
1308 1365 (strncmp(arg, "-_cc=", 5) == 0) ||
1309 1366 (strncmp(arg, "-_sun=", 6) == 0)) {
1310 1367 newae(ctx->i_ae, strchr(arg, '=') + 1);
1311 1368 }
1312 1369 break;
1313 1370
1314 1371 case 'V':
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
1315 1372 ctx->i_flags &= ~CW_F_ECHO;
1316 1373 newae(ctx->i_ae, arg);
1317 1374 break;
1318 1375 case 'o':
1319 1376 seen_o = 1;
1320 1377 if (strlen(arg) == 2) {
1321 1378 in_output = 1;
1322 1379 newae(ctx->i_ae, arg);
1323 1380 } else if (ctx->i_flags & CW_F_SHADOW) {
1324 1381 newae(ctx->i_ae, "-o");
1325 - newae(ctx->i_ae, ctx->i_discard);
1382 + newae(ctx->i_ae, discard_file_name(ctx, arg));
1326 1383 } else {
1327 1384 newae(ctx->i_ae, arg);
1328 1385 }
1329 1386 break;
1330 1387 case 'c':
1331 1388 case 'S':
1332 1389 if (strlen(arg) == 2)
1333 1390 op = CW_O_COMPILE;
1334 1391 newae(ctx->i_ae, arg);
1335 1392 break;
1336 1393 case 'E':
1337 1394 case 'P':
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
1338 1395 if (strlen(arg) == 2)
1339 1396 op = CW_O_PREPROCESS;
1340 1397 /*FALLTHROUGH*/
1341 1398 default:
1342 1399 newae(ctx->i_ae, arg);
1343 1400 }
1344 1401 }
1345 1402
1346 1403 free(nameflag);
1347 1404
1348 - if ((op == CW_O_LINK || op == CW_O_PREPROCESS) &&
1349 - (ctx->i_flags & CW_F_SHADOW))
1350 - exit(0);
1405 + /* See the comment on this same code in do_gcc() */
1406 + if (c_files > 1 && op != CW_O_PREPROCESS) {
1407 + errx(2, "multiple source files are "
1408 + "allowed only with -E or -P");
1409 + }
1410 +
1411 + if (ctx->i_flags & CW_F_SHADOW) {
1412 + if (op == CW_O_PREPROCESS)
1413 + exit(0);
1414 + else if (op == CW_O_LINK && c_files == 0)
1415 + exit(0);
1416 + }
1351 1417
1352 1418 if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1353 1419 newae(ctx->i_ae, "-o");
1354 - newae(ctx->i_ae, ctx->i_discard);
1420 + newae(ctx->i_ae, discard_file_name(ctx, NULL));
1355 1421 }
1356 1422 }
1357 1423
1358 1424 static void
1359 1425 prepctx(cw_ictx_t *ctx)
1360 1426 {
1361 1427 newae(ctx->i_ae, ctx->i_compiler->c_path);
1362 1428
1363 1429 if (ctx->i_flags & CW_F_PROG) {
1364 1430 (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
1365 1431 "shadow" : "primary", ctx->i_compiler->c_path);
1366 1432 (void) fflush(stdout);
1367 1433 }
1368 1434
1369 1435 if (!(ctx->i_flags & CW_F_XLATE))
1370 1436 return;
1371 1437
1372 1438 switch (ctx->i_compiler->c_style) {
1373 1439 case SUN:
1374 1440 do_cc(ctx);
1375 1441 break;
1376 1442 case GNU:
1377 1443 do_gcc(ctx);
1378 1444 break;
1379 1445 }
1380 1446 }
1381 1447
1382 1448 static int
1383 1449 invoke(cw_ictx_t *ctx)
1384 1450 {
1385 1451 char **newargv;
1386 1452 int ac;
1387 1453 struct ae *a;
1388 1454
1389 1455 if ((newargv = calloc(sizeof (*newargv), ctx->i_ae->ael_argc + 1)) ==
1390 1456 NULL)
1391 1457 nomem();
1392 1458
1393 1459 if (ctx->i_flags & CW_F_ECHO)
1394 1460 (void) fprintf(stderr, "+ ");
1395 1461
1396 1462 for (ac = 0, a = ctx->i_ae->ael_head; a; a = a->ae_next, ac++) {
1397 1463 newargv[ac] = a->ae_arg;
1398 1464 if (ctx->i_flags & CW_F_ECHO)
1399 1465 (void) fprintf(stderr, "%s ", a->ae_arg);
1400 1466 if (a == ctx->i_ae->ael_tail)
1401 1467 break;
1402 1468 }
1403 1469
1404 1470 if (ctx->i_flags & CW_F_ECHO) {
1405 1471 (void) fprintf(stderr, "\n");
1406 1472 (void) fflush(stderr);
1407 1473 }
1408 1474
1409 1475 if (!(ctx->i_flags & CW_F_EXEC))
1410 1476 return (0);
1411 1477
1412 1478 /*
1413 1479 * We must fix up the environment here so that the dependency files are
1414 1480 * not trampled by the shadow compiler. Also take care of GCC
1415 1481 * environment variables that will throw off gcc. This assumes a primary
1416 1482 * gcc.
1417 1483 */
1418 1484 if ((ctx->i_flags & CW_F_SHADOW) &&
1419 1485 (unsetenv("SUNPRO_DEPENDENCIES") != 0 ||
1420 1486 unsetenv("DEPENDENCIES_OUTPUT") != 0 ||
1421 1487 unsetenv("GCC_ROOT") != 0)) {
1422 1488 (void) fprintf(stderr, "error: environment setup failed: %s\n",
1423 1489 strerror(errno));
1424 1490 return (-1);
1425 1491 }
1426 1492
1427 1493 (void) execv(newargv[0], newargv);
1428 1494 warn("couldn't run %s", newargv[0]);
1429 1495
1430 1496 return (-1);
1431 1497 }
1432 1498
1433 1499 static int
1434 1500 reap(cw_ictx_t *ctx)
1435 1501 {
1436 1502 int status, ret = 0;
1437 1503 char buf[1024];
1438 1504 struct stat s;
1439 1505
1440 1506 /*
1441 1507 * Only wait for one specific child.
1442 1508 */
1443 1509 if (ctx->i_pid <= 0)
1444 1510 return (-1);
1445 1511
1446 1512 do {
1447 1513 if (waitpid(ctx->i_pid, &status, 0) < 0) {
1448 1514 warn("cannot reap child");
1449 1515 return (-1);
1450 1516 }
1451 1517 if (status != 0) {
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
1452 1518 if (WIFSIGNALED(status)) {
1453 1519 ret = -WTERMSIG(status);
1454 1520 break;
1455 1521 } else if (WIFEXITED(status)) {
1456 1522 ret = WEXITSTATUS(status);
1457 1523 break;
1458 1524 }
1459 1525 }
1460 1526 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
1461 1527
1462 - (void) unlink(ctx->i_discard);
1463 -
1464 1528 if (stat(ctx->i_stderr, &s) < 0) {
1465 1529 warn("stat failed on child cleanup");
1466 1530 return (-1);
1467 1531 }
1468 1532 if (s.st_size != 0) {
1469 1533 FILE *f;
1470 1534
1471 1535 if ((f = fopen(ctx->i_stderr, "r")) != NULL) {
1472 1536 while (fgets(buf, sizeof (buf), f))
1473 1537 (void) fprintf(stderr, "%s", buf);
1474 1538 (void) fflush(stderr);
1475 1539 (void) fclose(f);
1476 1540 }
1477 1541 }
1478 1542 (void) unlink(ctx->i_stderr);
1479 1543 free(ctx->i_stderr);
1480 1544
1481 1545 /*
1482 1546 * cc returns an error code when given -V; we want that to succeed.
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
1483 1547 */
1484 1548 if (ctx->i_flags & CW_F_PROG)
1485 1549 return (0);
1486 1550
1487 1551 return (ret);
1488 1552 }
1489 1553
1490 1554 static int
1491 1555 exec_ctx(cw_ictx_t *ctx, int block)
1492 1556 {
1493 - char *file;
1494 -
1495 - /*
1496 - * To avoid offending cc's sensibilities, the name of its output
1497 - * file must end in '.o'.
1498 - */
1499 - if ((file = tempnam(NULL, ".cw")) == NULL) {
1500 - nomem();
1501 - return (-1);
1502 - }
1503 - (void) strlcpy(ctx->i_discard, file, MAXPATHLEN);
1504 - (void) strlcat(ctx->i_discard, ".o", MAXPATHLEN);
1505 - free(file);
1506 -
1507 - if ((ctx->i_stderr = tempnam(NULL, ".cw")) == NULL) {
1557 + if ((ctx->i_stderr = tempnam(ctx->i_tmpdir, "cw")) == NULL) {
1508 1558 nomem();
1509 1559 return (-1);
1510 1560 }
1511 1561
1512 1562 if ((ctx->i_pid = fork()) == 0) {
1513 1563 int fd;
1514 1564
1515 1565 (void) fclose(stderr);
1516 1566 if ((fd = open(ctx->i_stderr, O_WRONLY | O_CREAT | O_EXCL,
1517 1567 0666)) < 0) {
1518 1568 err(1, "open failed for standard error");
1519 1569 }
1520 1570 if (dup2(fd, 2) < 0) {
1521 1571 err(1, "dup2 failed for standard error");
1522 1572 }
1523 1573 if (fd != 2)
1524 1574 (void) close(fd);
1525 1575 if (freopen("/dev/fd/2", "w", stderr) == NULL) {
1526 1576 err(1, "freopen failed for /dev/fd/2");
1527 1577 }
1528 1578
1529 1579 prepctx(ctx);
1530 1580 exit(invoke(ctx));
1531 1581 }
1532 1582
1533 1583 if (ctx->i_pid < 0) {
1534 1584 err(1, "fork failed");
1535 1585 }
1536 1586
1537 1587 if (block)
1538 1588 return (reap(ctx));
1539 1589
1540 1590 return (0);
1541 1591 }
1542 1592
1543 1593 static void
1544 1594 parse_compiler(const char *spec, cw_compiler_t *compiler)
1545 1595 {
1546 1596 char *tspec, *token;
1547 1597
1548 1598 if ((tspec = strdup(spec)) == NULL)
1549 1599 nomem();
1550 1600
1551 1601 if ((token = strsep(&tspec, ",")) == NULL)
1552 1602 errx(1, "Compiler is missing a name: %s", spec);
1553 1603 compiler->c_name = token;
1554 1604
1555 1605 if ((token = strsep(&tspec, ",")) == NULL)
1556 1606 errx(1, "Compiler is missing a path: %s", spec);
1557 1607 compiler->c_path = token;
1558 1608
1559 1609 if ((token = strsep(&tspec, ",")) == NULL)
1560 1610 errx(1, "Compiler is missing a style: %s", spec);
1561 1611
1562 1612 if ((strcasecmp(token, "gnu") == 0) ||
1563 1613 (strcasecmp(token, "gcc") == 0))
1564 1614 compiler->c_style = GNU;
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
1565 1615 else if ((strcasecmp(token, "sun") == 0) ||
1566 1616 (strcasecmp(token, "cc") == 0))
1567 1617 compiler->c_style = SUN;
1568 1618 else
1569 1619 errx(1, "unknown compiler style: %s", token);
1570 1620
1571 1621 if (tspec != NULL)
1572 1622 errx(1, "Excess tokens in compiler: %s", spec);
1573 1623 }
1574 1624
1625 +static void
1626 +cleanup(cw_ictx_t *ctx)
1627 +{
1628 + DIR *dirp;
1629 + struct dirent *dp;
1630 + char buf[MAXPATHLEN];
1631 +
1632 + if ((dirp = opendir(ctx->i_tmpdir)) == NULL) {
1633 + if (errno != ENOENT) {
1634 + err(1, "couldn't open temp directory: %s",
1635 + ctx->i_tmpdir);
1636 + } else {
1637 + return;
1638 + }
1639 + }
1640 +
1641 + errno = 0;
1642 + while ((dp = readdir(dirp)) != NULL) {
1643 + (void) snprintf(buf, MAXPATHLEN, "%s/%s", ctx->i_tmpdir,
1644 + dp->d_name);
1645 +
1646 + if (strncmp(dp->d_name, ".", strlen(dp->d_name)) == 0 ||
1647 + strncmp(dp->d_name, "..", strlen(dp->d_name)) == 0)
1648 + continue;
1649 +
1650 + if (unlink(buf) == -1)
1651 + err(1, "failed to unlink temp file: %s", dp->d_name);
1652 + errno = 0;
1653 + }
1654 +
1655 + if (errno != 0) {
1656 + err(1, "failed to read temporary directory: %s",
1657 + ctx->i_tmpdir);
1658 + }
1659 +
1660 + (void) closedir(dirp);
1661 + if (rmdir(ctx->i_tmpdir) != 0) {
1662 + err(1, "failed to unlink temporary directory: %s",
1663 + ctx->i_tmpdir);
1664 + }
1665 +}
1666 +
1575 1667 int
1576 1668 main(int argc, char **argv)
1577 1669 {
1578 1670 int ch;
1579 1671 cw_compiler_t primary = { NULL, NULL, 0 };
1580 1672 cw_compiler_t shadows[10];
1581 1673 int nshadows = 0;
1582 1674 int ret = 0;
1583 1675 boolean_t do_serial = B_FALSE;
1584 1676 boolean_t do_exec = B_FALSE;
1585 1677 boolean_t vflg = B_FALSE;
1586 1678 boolean_t Cflg = B_FALSE;
1587 1679 boolean_t cflg = B_FALSE;
1588 1680 boolean_t nflg = B_FALSE;
1681 + char *tmpdir;
1589 1682
1590 1683 cw_ictx_t *main_ctx;
1591 1684
1592 1685 static struct option longopts[] = {
1593 1686 { "compiler", no_argument, NULL, 'c' },
1594 1687 { "noecho", no_argument, NULL, 'n' },
1595 1688 { "primary", required_argument, NULL, 'p' },
1596 1689 { "shadow", required_argument, NULL, 's' },
1597 1690 { "versions", no_argument, NULL, 'v' },
1598 1691 { NULL, 0, NULL, 0 },
1599 1692 };
1600 1693
1601 1694
1602 1695 if ((main_ctx = newictx()) == NULL)
1603 1696 nomem();
1604 1697
1605 1698 while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) {
1606 1699 switch (ch) {
1607 1700 case 'c':
1608 1701 cflg = B_TRUE;
1609 1702 break;
1610 1703 case 'C':
1611 1704 Cflg = B_TRUE;
1612 1705 break;
1613 1706 case 'n':
1614 1707 nflg = B_TRUE;
1615 1708 break;
1616 1709 case 'p':
1617 1710 if (primary.c_path != NULL) {
1618 1711 warnx("Only one primary compiler may "
1619 1712 "be specified");
1620 1713 usage();
1621 1714 }
1622 1715
1623 1716 parse_compiler(optarg, &primary);
1624 1717 break;
1625 1718 case 's':
1626 1719 if (nshadows >= 10)
1627 1720 errx(1, "May only use 10 shadows at "
1628 1721 "the moment");
1629 1722 parse_compiler(optarg, &shadows[nshadows]);
1630 1723 nshadows++;
1631 1724 break;
1632 1725 case 'v':
1633 1726 vflg = B_TRUE;
1634 1727 break;
1635 1728 default:
1636 1729 (void) fprintf(stderr, "Did you forget '--'?\n");
1637 1730 usage();
1638 1731 }
1639 1732 }
1640 1733
1641 1734 if (primary.c_path == NULL) {
1642 1735 warnx("A primary compiler must be specified");
1643 1736 usage();
1644 1737 }
1645 1738
1646 1739 do_serial = (getenv("CW_SHADOW_SERIAL") == NULL) ? B_FALSE : B_TRUE;
1647 1740 do_exec = (getenv("CW_NO_EXEC") == NULL) ? B_TRUE : B_FALSE;
1648 1741
1649 1742 /* Leave room for argv[0] */
1650 1743 argc -= (optind - 1);
1651 1744 argv += (optind - 1);
1652 1745
1653 1746 main_ctx->i_oldargc = argc;
1654 1747 main_ctx->i_oldargv = argv;
1655 1748 main_ctx->i_flags = CW_F_XLATE;
1656 1749 if (nflg == 0)
1657 1750 main_ctx->i_flags |= CW_F_ECHO;
1658 1751 if (do_exec)
1659 1752 main_ctx->i_flags |= CW_F_EXEC;
1660 1753 if (Cflg)
1661 1754 main_ctx->i_flags |= CW_F_CXX;
1662 1755 main_ctx->i_compiler = &primary;
1663 1756
1664 1757 if (cflg) {
1665 1758 (void) fputs(primary.c_path, stdout);
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
1666 1759 }
1667 1760
1668 1761 if (vflg) {
1669 1762 (void) printf("cw version %s\n", CW_VERSION);
1670 1763 (void) fflush(stdout);
1671 1764 main_ctx->i_flags &= ~CW_F_ECHO;
1672 1765 main_ctx->i_flags |= CW_F_PROG | CW_F_EXEC;
1673 1766 do_serial = 1;
1674 1767 }
1675 1768
1769 + tmpdir = getenv("TMPDIR");
1770 + if (tmpdir == NULL)
1771 + tmpdir = "/tmp";
1772 +
1773 + if (asprintf(&main_ctx->i_tmpdir, "%s/cw.XXXXXX", tmpdir) == -1)
1774 + nomem();
1775 +
1776 + if ((main_ctx->i_tmpdir = mkdtemp(main_ctx->i_tmpdir)) == NULL)
1777 + errx(1, "failed to create temporary directory");
1778 +
1676 1779 ret |= exec_ctx(main_ctx, do_serial);
1677 1780
1678 1781 for (int i = 0; i < nshadows; i++) {
1679 1782 int r;
1680 1783 cw_ictx_t *shadow_ctx;
1681 1784
1682 1785 if ((shadow_ctx = newictx()) == NULL)
1683 1786 nomem();
1684 1787
1685 - memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t));
1788 + (void) memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t));
1686 1789
1687 1790 shadow_ctx->i_flags |= CW_F_SHADOW;
1688 1791 shadow_ctx->i_compiler = &shadows[i];
1689 1792
1690 1793 r = exec_ctx(shadow_ctx, do_serial);
1691 1794 if (r == 0) {
1692 1795 shadow_ctx->i_next = main_ctx->i_next;
1693 1796 main_ctx->i_next = shadow_ctx;
1694 1797 }
1695 1798 ret |= r;
1696 1799 }
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
1697 1800
1698 1801 if (!do_serial) {
1699 1802 cw_ictx_t *next = main_ctx;
1700 1803 while (next != NULL) {
1701 1804 cw_ictx_t *toreap = next;
1702 1805 next = next->i_next;
1703 1806 ret |= reap(toreap);
1704 1807 }
1705 1808 }
1706 1809
1810 + cleanup(main_ctx);
1707 1811 return (ret);
1708 1812 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX