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