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