17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 502e56f3fSwesolows * Common Development and Distribution License (the "License"). 602e56f3fSwesolows * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2102e56f3fSwesolows 227c478bd9Sstevel@tonic-gate /* 23*80ab886dSwesolows * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Wrapper for the GNU C compiler to make it accept the Sun C compiler 317c478bd9Sstevel@tonic-gate * arguments where possible. 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * Since the translation is inexact, this is something of a work-in-progress. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * -# Verbose mode 387c478bd9Sstevel@tonic-gate * -### Show compiler commands built by driver, no compilation 397c478bd9Sstevel@tonic-gate * -A<name[(tokens)]> Preprocessor predicate assertion 407c478bd9Sstevel@tonic-gate * -B<[static|dynamic]> Specify dynamic or static binding 417c478bd9Sstevel@tonic-gate * -C Prevent preprocessor from removing comments 427c478bd9Sstevel@tonic-gate * -c Compile only - produce .o files, suppress linking 437c478bd9Sstevel@tonic-gate * -cg92 Alias for -xtarget=ss1000 447c478bd9Sstevel@tonic-gate * -D<name[=token]> Associate name with token as if by #define 457c478bd9Sstevel@tonic-gate * -d[y|n] dynamic [-dy] or static [-dn] option to linker 467c478bd9Sstevel@tonic-gate * -E Compile source through preprocessor only, output to stdout 477c478bd9Sstevel@tonic-gate * -erroff=<t> Suppress warnings specified by tags t(%none, %all, <tag list>) 487c478bd9Sstevel@tonic-gate * -errtags=<a> Display messages with tags a(no, yes) 497c478bd9Sstevel@tonic-gate * -errwarn=<t> Treats warnings specified by tags t(%none, %all, <tag list>) 507c478bd9Sstevel@tonic-gate * as errors 517c478bd9Sstevel@tonic-gate * -fast Optimize using a selection of options 527c478bd9Sstevel@tonic-gate * -fd Report old-style function definitions and declarations 537c478bd9Sstevel@tonic-gate * -flags Show this summary of compiler options 547c478bd9Sstevel@tonic-gate * -fnonstd Initialize floating-point hardware to non-standard preferences 557c478bd9Sstevel@tonic-gate * -fns[=<yes|no>] Select non-standard floating point mode 567c478bd9Sstevel@tonic-gate * -fprecision=<p> Set FP rounding precision mode p(single, double, extended) 577c478bd9Sstevel@tonic-gate * -fround=<r> Select the IEEE rounding mode in effect at startup 587c478bd9Sstevel@tonic-gate * -fsimple[=<n>] Select floating-point optimization preferences <n> 597c478bd9Sstevel@tonic-gate * -fsingle Use single-precision arithmetic (-Xt and -Xs modes only) 607c478bd9Sstevel@tonic-gate * -ftrap=<t> Select floating-point trapping mode in effect at startup 617c478bd9Sstevel@tonic-gate * -fstore force floating pt. values to target precision on assignment 627c478bd9Sstevel@tonic-gate * -G Build a dynamic shared library 637c478bd9Sstevel@tonic-gate * -g Compile for debugging 647c478bd9Sstevel@tonic-gate * -H Print path name of each file included during compilation 657c478bd9Sstevel@tonic-gate * -h <name> Assign <name> to generated dynamic shared library 667c478bd9Sstevel@tonic-gate * -I<dir> Add <dir> to preprocessor #include file search path 677c478bd9Sstevel@tonic-gate * -i Passed to linker to ignore any LD_LIBRARY_PATH setting 687c478bd9Sstevel@tonic-gate * -keeptmp Keep temporary files created during compilation 697c478bd9Sstevel@tonic-gate * -KPIC Compile position independent code with 32-bit addresses 707c478bd9Sstevel@tonic-gate * -Kpic Compile position independent code 717c478bd9Sstevel@tonic-gate * -L<dir> Pass to linker to add <dir> to the library search path 727c478bd9Sstevel@tonic-gate * -l<name> Link with library lib<name>.a or lib<name>.so 737c478bd9Sstevel@tonic-gate * -mc Remove duplicate strings from .comment section of output files 747c478bd9Sstevel@tonic-gate * -mr Remove all strings from .comment section of output files 757c478bd9Sstevel@tonic-gate * -mr,"string" Remove all strings and append "string" to .comment section 767c478bd9Sstevel@tonic-gate * -mt Specify options needed when compiling multi-threaded code 777c478bd9Sstevel@tonic-gate * -native Find available processor, generate code accordingly 787c478bd9Sstevel@tonic-gate * -nofstore Do not force floating pt. values to target precision 797c478bd9Sstevel@tonic-gate * on assignment 807c478bd9Sstevel@tonic-gate * -nolib Same as -xnolib 817c478bd9Sstevel@tonic-gate * -noqueue Disable queuing of compiler license requests 827c478bd9Sstevel@tonic-gate * -norunpath Do not build in a runtime path for shared libraries 83662492f5Ssherrym * -O Use default optimization level (-xO2 or -xO3. Check man page.) 847c478bd9Sstevel@tonic-gate * -o <outputfile> Set name of output file to <outputfile> 857c478bd9Sstevel@tonic-gate * -P Compile source through preprocessor only, output to .i file 867c478bd9Sstevel@tonic-gate * -PIC Alias for -KPIC or -xcode=pic32 877c478bd9Sstevel@tonic-gate * -p Compile for profiling with prof 887c478bd9Sstevel@tonic-gate * -pic Alias for -Kpic or -xcode=pic13 897c478bd9Sstevel@tonic-gate * -Q[y|n] Emit/don't emit identification info to output file 907c478bd9Sstevel@tonic-gate * -qp Compile for profiling with prof 917c478bd9Sstevel@tonic-gate * -R<dir[:dir]> Build runtime search path list into executable 927c478bd9Sstevel@tonic-gate * -S Compile and only generate assembly code (.s) 937c478bd9Sstevel@tonic-gate * -s Strip symbol table from the executable file 94159cf8a6Swesolows * -t Turn off duplicate symbol warnings when linking 957c478bd9Sstevel@tonic-gate * -U<name> Delete initial definition of preprocessor symbol <name> 967c478bd9Sstevel@tonic-gate * -V Report version number of each compilation phase 977c478bd9Sstevel@tonic-gate * -v Do stricter semantic checking 987c478bd9Sstevel@tonic-gate * -W<c>,<arg> Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u) 997c478bd9Sstevel@tonic-gate * -w Suppress compiler warning messages 1007c478bd9Sstevel@tonic-gate * -Xa Compile assuming ANSI C conformance, allow K & R extensions 1017c478bd9Sstevel@tonic-gate * (default mode) 1027c478bd9Sstevel@tonic-gate * -Xc Compile assuming strict ANSI C conformance 1037c478bd9Sstevel@tonic-gate * -Xs Compile assuming (pre-ANSI) K & R C style code 1047c478bd9Sstevel@tonic-gate * -Xt Compile assuming K & R conformance, allow ANSI C 1057c478bd9Sstevel@tonic-gate * -x386 Generate code for the 80386 processor 1067c478bd9Sstevel@tonic-gate * -x486 Generate code for the 80486 processor 1077c478bd9Sstevel@tonic-gate * -xarch=<a> Specify target architecture instruction set 1087c478bd9Sstevel@tonic-gate * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions 1097c478bd9Sstevel@tonic-gate * for system functions, b={%all,%none} 1107c478bd9Sstevel@tonic-gate * -xCC Accept C++ style comments 1117c478bd9Sstevel@tonic-gate * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low) 1127c478bd9Sstevel@tonic-gate * -xchip=<c> Specify the target processor for use by the optimizer 1137c478bd9Sstevel@tonic-gate * -xcode=<c> Generate different code for forming addresses 1147c478bd9Sstevel@tonic-gate * -xcrossfile[=<n>] Enable optimization and inlining across source files, 1157c478bd9Sstevel@tonic-gate * n={0|1} 1167c478bd9Sstevel@tonic-gate * -xe Perform only syntax/semantic checking, no code generation 1177c478bd9Sstevel@tonic-gate * -xF Compile for later mapfile reordering 1187c478bd9Sstevel@tonic-gate * -xhelp=<f> Display on-line help information f(flags, readme, errors) 1197c478bd9Sstevel@tonic-gate * -xildoff Cancel -xildon 1207c478bd9Sstevel@tonic-gate * -xildon Enable use of the incremental linker, ild 1217c478bd9Sstevel@tonic-gate * -xinline=[<a>,...,<a>] Attempt inlining of specified user routines, 1227c478bd9Sstevel@tonic-gate * <a>={%auto,func,no%func} 1237c478bd9Sstevel@tonic-gate * -xlibmieee Force IEEE 754 return values for math routines in 1247c478bd9Sstevel@tonic-gate * exceptional cases 1257c478bd9Sstevel@tonic-gate * -xlibmil Inline selected libm math routines for optimization 1267c478bd9Sstevel@tonic-gate * -xlic_lib=sunperf Link in the Sun supplied performance libraries 1277c478bd9Sstevel@tonic-gate * -xlicinfo Show license server information 1287c478bd9Sstevel@tonic-gate * -xM Generate makefile dependencies 1297c478bd9Sstevel@tonic-gate * -xM1 Generate makefile dependencies, but exclude /usr/include 1307c478bd9Sstevel@tonic-gate * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt 1317c478bd9Sstevel@tonic-gate * -xnolib Do not link with default system libraries 1327c478bd9Sstevel@tonic-gate * -xnolibmil Cancel -xlibmil on command line 1337c478bd9Sstevel@tonic-gate * -xO<n> Generate optimized code (n={1|2|3|4|5}) 1347c478bd9Sstevel@tonic-gate * -xP Print prototypes for function definitions 1357c478bd9Sstevel@tonic-gate * -xpentium Generate code for the pentium processor 1367c478bd9Sstevel@tonic-gate * -xpg Compile for profiling with gprof 1377c478bd9Sstevel@tonic-gate * -xprofile=<p> Collect data for a profile or use a profile to optimize 1387c478bd9Sstevel@tonic-gate * <p>={{collect,use}[:<path>],tcov} 1397c478bd9Sstevel@tonic-gate * -xregs=<r> Control register allocation 1407c478bd9Sstevel@tonic-gate * -xs Allow debugging without object (.o) files 1417c478bd9Sstevel@tonic-gate * -xsb Compile for use with the WorkShop source browser 1427c478bd9Sstevel@tonic-gate * -xsbfast Generate only WorkShop source browser info, no compilation 1437c478bd9Sstevel@tonic-gate * -xsfpconst Represent unsuffixed floating point constants as single 1447c478bd9Sstevel@tonic-gate * precision 1457c478bd9Sstevel@tonic-gate * -xspace Do not do optimizations that increase code size 1467c478bd9Sstevel@tonic-gate * -xstrconst Place string literals into read-only data segment 1477c478bd9Sstevel@tonic-gate * -xtarget=<t> Specify target system for optimization 1487c478bd9Sstevel@tonic-gate * -xtemp=<dir> Set directory for temporary files to <dir> 1497c478bd9Sstevel@tonic-gate * -xtime Report the execution time for each compilation phase 1507c478bd9Sstevel@tonic-gate * -xtransition Emit warnings for differences between K&R C and ANSI C 1517c478bd9Sstevel@tonic-gate * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation 1527c478bd9Sstevel@tonic-gate * -xunroll=n Enable unrolling loops n times where possible 1537c478bd9Sstevel@tonic-gate * -Y<c>,<dir> Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u) 1547c478bd9Sstevel@tonic-gate * -YA,<dir> Change default directory searched for components 1557c478bd9Sstevel@tonic-gate * -YI,<dir> Change default directory searched for include files 1567c478bd9Sstevel@tonic-gate * -YP,<dir> Change default directory for finding libraries files 1577c478bd9Sstevel@tonic-gate * -YS,<dir> Change default directory for startup object files 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * Translation table: 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * -# -v 1657c478bd9Sstevel@tonic-gate * -### error 1667c478bd9Sstevel@tonic-gate * -A<name[(tokens)]> pass-thru 1677c478bd9Sstevel@tonic-gate * -B<[static|dynamic]> pass-thru (syntax error for anything else) 1687c478bd9Sstevel@tonic-gate * -C pass-thru 1697c478bd9Sstevel@tonic-gate * -c pass-thru 1707c478bd9Sstevel@tonic-gate * -cg92 -m32 -mcpu=v8 -mtune=supersparc (SPARC only) 1717c478bd9Sstevel@tonic-gate * -D<name[=token]> pass-thru 1727c478bd9Sstevel@tonic-gate * -dy or -dn -Wl,-dy or -Wl,-dn 1737c478bd9Sstevel@tonic-gate * -E pass-thru 1747c478bd9Sstevel@tonic-gate * -erroff=E_EMPTY_TRANSLATION_UNIT ignore 1757c478bd9Sstevel@tonic-gate * -errtags=%all -Wall 1767c478bd9Sstevel@tonic-gate * -errwarn=%all -Werror else -Wno-error 1777c478bd9Sstevel@tonic-gate * -fast error 1787c478bd9Sstevel@tonic-gate * -fd error 1797c478bd9Sstevel@tonic-gate * -flags --help 1807c478bd9Sstevel@tonic-gate * -fnonstd error 1817c478bd9Sstevel@tonic-gate * -fns[=<yes|no>] error 1827c478bd9Sstevel@tonic-gate * -fprecision=<p> error 1837c478bd9Sstevel@tonic-gate * -fround=<r> error 1847c478bd9Sstevel@tonic-gate * -fsimple[=<n>] error 1857c478bd9Sstevel@tonic-gate * -fsingle[=<n>] error 1867c478bd9Sstevel@tonic-gate * -ftrap=<t> error 1877c478bd9Sstevel@tonic-gate * -fstore error 1887c478bd9Sstevel@tonic-gate * -G pass-thru 1897c478bd9Sstevel@tonic-gate * -g pass-thru 1907c478bd9Sstevel@tonic-gate * -H pass-thru 1917c478bd9Sstevel@tonic-gate * -h <name> pass-thru 1927c478bd9Sstevel@tonic-gate * -I<dir> pass-thru 1937c478bd9Sstevel@tonic-gate * -i pass-thru 1947c478bd9Sstevel@tonic-gate * -keeptmp -save-temps 1957c478bd9Sstevel@tonic-gate * -KPIC -fPIC 1967c478bd9Sstevel@tonic-gate * -Kpic -fpic 1977c478bd9Sstevel@tonic-gate * -L<dir> pass-thru 1987c478bd9Sstevel@tonic-gate * -l<name> pass-thru 1997c478bd9Sstevel@tonic-gate * -mc error 2007c478bd9Sstevel@tonic-gate * -mr error 2017c478bd9Sstevel@tonic-gate * -mr,"string" error 2027c478bd9Sstevel@tonic-gate * -mt -D_REENTRANT 2037c478bd9Sstevel@tonic-gate * -native error 2047c478bd9Sstevel@tonic-gate * -nofstore error 2057c478bd9Sstevel@tonic-gate * -nolib -nodefaultlibs 2067c478bd9Sstevel@tonic-gate * -noqueue ignore 2077c478bd9Sstevel@tonic-gate * -norunpath ignore 208662492f5Ssherrym * -O -O1 (Check the man page to be certain) 2097c478bd9Sstevel@tonic-gate * -o <outputfile> pass-thru 2107c478bd9Sstevel@tonic-gate * -P -E -o filename.i (or error) 2117c478bd9Sstevel@tonic-gate * -PIC -fPIC (C++ only) 2127c478bd9Sstevel@tonic-gate * -p pass-thru 2137c478bd9Sstevel@tonic-gate * -pic -fpic (C++ only) 2147c478bd9Sstevel@tonic-gate * -Q[y|n] error 2157c478bd9Sstevel@tonic-gate * -qp -p 2167c478bd9Sstevel@tonic-gate * -R<dir[:dir]> pass-thru 2177c478bd9Sstevel@tonic-gate * -S pass-thru 2187c478bd9Sstevel@tonic-gate * -s -Wl,-s 219159cf8a6Swesolows * -t -Wl,-t 2207c478bd9Sstevel@tonic-gate * -U<name> pass-thru 2217c478bd9Sstevel@tonic-gate * -V --version 2227c478bd9Sstevel@tonic-gate * -v -Wall 2237c478bd9Sstevel@tonic-gate * -Wa,<arg> pass-thru 2247c478bd9Sstevel@tonic-gate * -Wp,<arg> pass-thru except -xc99=<a> 2257c478bd9Sstevel@tonic-gate * -Wl,<arg> pass-thru 2267c478bd9Sstevel@tonic-gate * -W{m,0,2,h,i,u> error/ignore 2277c478bd9Sstevel@tonic-gate * -Wu,-xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone 228d430274bSsherrym * -Wu,-save_args -msave-args 2297c478bd9Sstevel@tonic-gate * -w pass-thru 2307c478bd9Sstevel@tonic-gate * -Xa -std=iso9899:199409 or -ansi 2317c478bd9Sstevel@tonic-gate * -Xc -ansi -pedantic 2327c478bd9Sstevel@tonic-gate * -Xt error 2337c478bd9Sstevel@tonic-gate * -Xs -traditional -std=c89 2347c478bd9Sstevel@tonic-gate * -x386 -march=i386 (x86 only) 2357c478bd9Sstevel@tonic-gate * -x486 -march=i486 (x86 only) 2367c478bd9Sstevel@tonic-gate * -xarch=<a> table 23702e56f3fSwesolows * -xbuiltin[=<b>] -fbuiltin (-fno-builtin otherwise) 2387c478bd9Sstevel@tonic-gate * -xCC ignore 2397c478bd9Sstevel@tonic-gate * -xchar_byte_order=<o> error 2407c478bd9Sstevel@tonic-gate * -xchip=<c> table 2417c478bd9Sstevel@tonic-gate * -xcode=<c> table 2428c1a3716Ssherrym * -xdebugformat=<format> ignore (always use dwarf-2 for gcc) 243159cf8a6Swesolows * -xcrossfile[=<n>] ignore 2447c478bd9Sstevel@tonic-gate * -xe error 2457c478bd9Sstevel@tonic-gate * -xF error 2467c478bd9Sstevel@tonic-gate * -xhelp=<f> error 2477c478bd9Sstevel@tonic-gate * -xildoff ignore 2487c478bd9Sstevel@tonic-gate * -xildon ignore 2497c478bd9Sstevel@tonic-gate * -xinline ignore 2507c478bd9Sstevel@tonic-gate * -xlibmieee error 2517c478bd9Sstevel@tonic-gate * -xlibmil error 2527c478bd9Sstevel@tonic-gate * -xlic_lib=sunperf error 2537c478bd9Sstevel@tonic-gate * -xM -M 2547c478bd9Sstevel@tonic-gate * -xM1 -MM 2557c478bd9Sstevel@tonic-gate * -xmaxopt=[...] error 2567c478bd9Sstevel@tonic-gate * -xnolib -nodefaultlibs 2577c478bd9Sstevel@tonic-gate * -xnolibmil error 2587c478bd9Sstevel@tonic-gate * -xO<n> -O<n> 2597c478bd9Sstevel@tonic-gate * -xP error 2607c478bd9Sstevel@tonic-gate * -xpentium -march=pentium (x86 only) 2617c478bd9Sstevel@tonic-gate * -xpg error 2627c478bd9Sstevel@tonic-gate * -xprofile=<p> error 2637c478bd9Sstevel@tonic-gate * -xregs=<r> table 2647c478bd9Sstevel@tonic-gate * -xs error 2657c478bd9Sstevel@tonic-gate * -xsb error 2667c478bd9Sstevel@tonic-gate * -xsbfast error 2677c478bd9Sstevel@tonic-gate * -xsfpconst error 2687c478bd9Sstevel@tonic-gate * -xspace ignore (-not -Os) 2697c478bd9Sstevel@tonic-gate * -xstrconst ignore 2707c478bd9Sstevel@tonic-gate * -xtarget=<t> table 2717c478bd9Sstevel@tonic-gate * -xtemp=<dir> error 2727c478bd9Sstevel@tonic-gate * -xtime error 2737c478bd9Sstevel@tonic-gate * -xtransition -Wtransition 2747c478bd9Sstevel@tonic-gate * -xtrigraphs=<yes|no> -trigraphs -notrigraphs 2757c478bd9Sstevel@tonic-gate * -xunroll=n error 2768c1a3716Ssherrym * -W0,-xdbggen=no%usedonly -fno-eliminate-unused-debug-symbols 2778c1a3716Ssherrym * -fno-eliminate-unused-debug-types 2787c478bd9Sstevel@tonic-gate * -Y<c>,<dir> error 2797c478bd9Sstevel@tonic-gate * -YA,<dir> error 2807c478bd9Sstevel@tonic-gate * -YI,<dir> -nostdinc -I<dir> 2817c478bd9Sstevel@tonic-gate * -YP,<dir> error 2827c478bd9Sstevel@tonic-gate * -YS,<dir> error 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate #include <stdio.h> 2867c478bd9Sstevel@tonic-gate #include <sys/types.h> 2877c478bd9Sstevel@tonic-gate #include <unistd.h> 2887c478bd9Sstevel@tonic-gate #include <string.h> 2897c478bd9Sstevel@tonic-gate #include <stdlib.h> 2907c478bd9Sstevel@tonic-gate #include <ctype.h> 291*80ab886dSwesolows #include <fcntl.h> 292*80ab886dSwesolows #include <errno.h> 293*80ab886dSwesolows #include <stdarg.h> 2947c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 2957c478bd9Sstevel@tonic-gate #include <sys/param.h> 2967c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 297*80ab886dSwesolows #include <sys/wait.h> 298*80ab886dSwesolows #include <sys/stat.h> 299*80ab886dSwesolows 300*80ab886dSwesolows #define CW_F_CXX 0x01 301*80ab886dSwesolows #define CW_F_SHADOW 0x02 302*80ab886dSwesolows #define CW_F_EXEC 0x04 303*80ab886dSwesolows #define CW_F_ECHO 0x08 304*80ab886dSwesolows #define CW_F_XLATE 0x10 305*80ab886dSwesolows 306*80ab886dSwesolows typedef enum cw_compiler { 307*80ab886dSwesolows CW_C_CC = 0, 308*80ab886dSwesolows CW_C_GCC 309*80ab886dSwesolows } cw_compiler_t; 310*80ab886dSwesolows 311*80ab886dSwesolows static const char *cmds[] = { 312*80ab886dSwesolows "cc", "CC", 313*80ab886dSwesolows "gcc", "g++" 314*80ab886dSwesolows }; 3157c478bd9Sstevel@tonic-gate 316*80ab886dSwesolows static const char *dirs[] = { 317*80ab886dSwesolows DEFAULT_CC_DIR, DEFAULT_CPLUSPLUS_DIR, 318*80ab886dSwesolows DEFAULT_GCC_DIR, DEFAULT_GPLUSPLUS_DIR 319*80ab886dSwesolows }; 3207c478bd9Sstevel@tonic-gate 321*80ab886dSwesolows #define CC(ctx) \ 322*80ab886dSwesolows (((ctx)->i_flags & CW_F_SHADOW) ? \ 323*80ab886dSwesolows ((ctx)->i_compiler == CW_C_CC ? CW_C_GCC : CW_C_CC) : \ 324*80ab886dSwesolows (ctx)->i_compiler) 3257c478bd9Sstevel@tonic-gate 326*80ab886dSwesolows #define CIDX(compiler, flags) \ 327*80ab886dSwesolows ((int)(compiler) << 1) + ((flags) & CW_F_CXX ? 1 : 0) 328*80ab886dSwesolows 329*80ab886dSwesolows typedef enum cw_op { 330*80ab886dSwesolows CW_O_NONE = 0, 331*80ab886dSwesolows CW_O_PREPROCESS, 332*80ab886dSwesolows CW_O_COMPILE, 333*80ab886dSwesolows CW_O_LINK 334*80ab886dSwesolows } cw_op_t; 335*80ab886dSwesolows 336*80ab886dSwesolows struct aelist { 337*80ab886dSwesolows struct ae { 338*80ab886dSwesolows struct ae *ae_next; 339*80ab886dSwesolows char *ae_arg; 340*80ab886dSwesolows } *ael_head, *ael_tail; 341*80ab886dSwesolows int ael_argc; 342*80ab886dSwesolows }; 343*80ab886dSwesolows 344*80ab886dSwesolows typedef struct cw_ictx { 345*80ab886dSwesolows cw_compiler_t i_compiler; 346*80ab886dSwesolows struct aelist *i_ae; 347*80ab886dSwesolows uint32_t i_flags; 348*80ab886dSwesolows int i_oldargc; 349*80ab886dSwesolows char **i_oldargv; 350*80ab886dSwesolows pid_t i_pid; 351*80ab886dSwesolows int i_fd[2]; 352*80ab886dSwesolows char i_discard[MAXPATHLEN]; 353*80ab886dSwesolows } cw_ictx_t; 354*80ab886dSwesolows 355*80ab886dSwesolows static const char *progname; 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate static const char *xarch_tbl[] = { 3587c478bd9Sstevel@tonic-gate #if defined(__x86) 3597c478bd9Sstevel@tonic-gate "generic", NULL, 3607c478bd9Sstevel@tonic-gate "generic64", "-m64", "-mtune=opteron", NULL, 3617c478bd9Sstevel@tonic-gate "amd64", "-m64", "-mtune=opteron", NULL, 3627c478bd9Sstevel@tonic-gate "386", "-march=i386", NULL, 3637c478bd9Sstevel@tonic-gate "pentium_pro", "-march=pentiumpro", NULL, 3647c478bd9Sstevel@tonic-gate #elif defined(__sparc) 3657c478bd9Sstevel@tonic-gate "generic", "-m32", "-mcpu=v8", NULL, 3667c478bd9Sstevel@tonic-gate "generic64", "-m64", "-mcpu=v9", NULL, 3677c478bd9Sstevel@tonic-gate "v8", "-m32", "-mcpu=v8", "-mno-v8plus", NULL, 3687c478bd9Sstevel@tonic-gate "v8plus", "-m32", "-mcpu=v9", "-mv8plus", NULL, 3697c478bd9Sstevel@tonic-gate "v8plusa", "-m32", "-mcpu=ultrasparc", "-mv8plus", "-mvis", NULL, 3707c478bd9Sstevel@tonic-gate "v8plusb", "-m32", "-mcpu=ultrasparc3", "-mv8plus", "-mvis", NULL, 3717c478bd9Sstevel@tonic-gate "v9", "-m64", "-mcpu=v9", NULL, 3727c478bd9Sstevel@tonic-gate "v9a", "-m64", "-mcpu=ultrasparc", "-mvis", NULL, 3737c478bd9Sstevel@tonic-gate "v9b", "-m64", "-mcpu=ultrasparc3", "-mvis", NULL, 3747c478bd9Sstevel@tonic-gate #endif 3757c478bd9Sstevel@tonic-gate NULL, NULL 3767c478bd9Sstevel@tonic-gate }; 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate static const char *xchip_tbl[] = { 3797c478bd9Sstevel@tonic-gate #if defined(__x86) 3807c478bd9Sstevel@tonic-gate "386", "-mtune=i386", NULL, 3817c478bd9Sstevel@tonic-gate "486", "-mtune=i486", NULL, 3827c478bd9Sstevel@tonic-gate "pentium", "-mtune=pentium", NULL, 3837c478bd9Sstevel@tonic-gate "pentium_pro", "-mtune=pentiumpro", NULL, 3847c478bd9Sstevel@tonic-gate #elif defined(__sparc) 3857c478bd9Sstevel@tonic-gate "super", "-mtune=supersparc", NULL, 3867c478bd9Sstevel@tonic-gate "ultra", "-mtune=ultrasparc", NULL, 3877c478bd9Sstevel@tonic-gate "ultra3", "-mtune=ultrasparc3", NULL, 3887c478bd9Sstevel@tonic-gate #endif 3897c478bd9Sstevel@tonic-gate NULL, NULL 3907c478bd9Sstevel@tonic-gate }; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate static const char *xcode_tbl[] = { 3937c478bd9Sstevel@tonic-gate #if defined(__sparc) 3947c478bd9Sstevel@tonic-gate "abs32", "-fno-pic", "-mcmodel=medlow", NULL, 3957c478bd9Sstevel@tonic-gate "abs44", "-fno-pic", "-mcmodel=medmid", NULL, 3967c478bd9Sstevel@tonic-gate "abs64", "-fno-pic", "-mcmodel=medany", NULL, 3977c478bd9Sstevel@tonic-gate "pic13", "-fpic", NULL, 3987c478bd9Sstevel@tonic-gate "pic32", "-fPIC", NULL, 3997c478bd9Sstevel@tonic-gate #endif 4007c478bd9Sstevel@tonic-gate NULL, NULL 4017c478bd9Sstevel@tonic-gate }; 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate static const char *xtarget_tbl[] = { 4047c478bd9Sstevel@tonic-gate #if defined(__x86) 4057c478bd9Sstevel@tonic-gate "pentium_pro", "-march=pentiumpro", NULL, 4067c478bd9Sstevel@tonic-gate #endif /* __x86 */ 4077c478bd9Sstevel@tonic-gate NULL, NULL 4087c478bd9Sstevel@tonic-gate }; 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate static const char *xregs_tbl[] = { 4117c478bd9Sstevel@tonic-gate #if defined(__sparc) 4127c478bd9Sstevel@tonic-gate "appl", "-mapp-regs", NULL, 4137c478bd9Sstevel@tonic-gate "no%appl", "-mno-app-regs", NULL, 4147c478bd9Sstevel@tonic-gate "float", "-mfpu", NULL, 4157c478bd9Sstevel@tonic-gate "no%float", "-mno-fpu", NULL, 4167c478bd9Sstevel@tonic-gate #endif /* __sparc */ 4177c478bd9Sstevel@tonic-gate NULL, NULL 4187c478bd9Sstevel@tonic-gate }; 4197c478bd9Sstevel@tonic-gate 420*80ab886dSwesolows static void 421*80ab886dSwesolows nomem(void) 422*80ab886dSwesolows { 423*80ab886dSwesolows (void) fprintf(stderr, "%s: error: out of memory\n", progname); 424*80ab886dSwesolows exit(1); 425*80ab886dSwesolows } 4267c478bd9Sstevel@tonic-gate 427*80ab886dSwesolows static void 428*80ab886dSwesolows cw_perror(const char *fmt, ...) 4297c478bd9Sstevel@tonic-gate { 430*80ab886dSwesolows va_list ap; 431*80ab886dSwesolows int saved_errno = errno; 432*80ab886dSwesolows 433*80ab886dSwesolows (void) fprintf(stderr, "%s: error: ", progname); 434*80ab886dSwesolows 435*80ab886dSwesolows va_start(ap, fmt); 436*80ab886dSwesolows (void) vfprintf(stderr, fmt, ap); 437*80ab886dSwesolows va_end(ap); 438*80ab886dSwesolows 439*80ab886dSwesolows (void) fprintf(stderr, " (%s)\n", strerror(saved_errno)); 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate static void 4437c478bd9Sstevel@tonic-gate newae(struct aelist *ael, const char *arg) 4447c478bd9Sstevel@tonic-gate { 4457c478bd9Sstevel@tonic-gate struct ae *ae; 4467c478bd9Sstevel@tonic-gate 447*80ab886dSwesolows if ((ae = calloc(sizeof (*ae), 1)) == NULL) 448*80ab886dSwesolows nomem(); 4497c478bd9Sstevel@tonic-gate ae->ae_arg = strdup(arg); 4507c478bd9Sstevel@tonic-gate if (ael->ael_tail == NULL) 4517c478bd9Sstevel@tonic-gate ael->ael_head = ae; 4527c478bd9Sstevel@tonic-gate else 4537c478bd9Sstevel@tonic-gate ael->ael_tail->ae_next = ae; 4547c478bd9Sstevel@tonic-gate ael->ael_tail = ae; 455*80ab886dSwesolows ael->ael_argc++; 456*80ab886dSwesolows } 457*80ab886dSwesolows 458*80ab886dSwesolows static cw_ictx_t * 459*80ab886dSwesolows newictx(void) 460*80ab886dSwesolows { 461*80ab886dSwesolows cw_ictx_t *ctx = calloc(sizeof (cw_ictx_t), 1); 462*80ab886dSwesolows if (ctx) 463*80ab886dSwesolows if ((ctx->i_ae = calloc(sizeof (struct aelist), 1)) == NULL) { 464*80ab886dSwesolows free(ctx); 465*80ab886dSwesolows return (NULL); 466*80ab886dSwesolows } 467*80ab886dSwesolows 468*80ab886dSwesolows return (ctx); 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate static void 4727c478bd9Sstevel@tonic-gate error(const char *arg) 4737c478bd9Sstevel@tonic-gate { 4747c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 475*80ab886dSwesolows "%s: error: mapping failed at or near arg '%s'\n", progname, arg); 4767c478bd9Sstevel@tonic-gate exit(2); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* 4807c478bd9Sstevel@tonic-gate * Add the current favourite set of warnings to the gcc invocation. 4817c478bd9Sstevel@tonic-gate */ 4827c478bd9Sstevel@tonic-gate static void 4837c478bd9Sstevel@tonic-gate warnings(struct aelist *h) 4847c478bd9Sstevel@tonic-gate { 4857c478bd9Sstevel@tonic-gate static int warningsonce; 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate if (warningsonce++) 4887c478bd9Sstevel@tonic-gate return; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate newae(h, "-Wall"); 4917c478bd9Sstevel@tonic-gate newae(h, "-Wno-unknown-pragmas"); 4927c478bd9Sstevel@tonic-gate newae(h, "-Wno-missing-braces"); 4937c478bd9Sstevel@tonic-gate newae(h, "-Wno-sign-compare"); 4947c478bd9Sstevel@tonic-gate newae(h, "-Wno-parentheses"); 4957c478bd9Sstevel@tonic-gate newae(h, "-Wno-uninitialized"); 4967c478bd9Sstevel@tonic-gate newae(h, "-Wno-implicit-function-declaration"); 4977c478bd9Sstevel@tonic-gate newae(h, "-Wno-unused"); 4987c478bd9Sstevel@tonic-gate newae(h, "-Wno-trigraphs"); 4997c478bd9Sstevel@tonic-gate newae(h, "-Wno-char-subscripts"); 5007c478bd9Sstevel@tonic-gate newae(h, "-Wno-switch"); 5017c478bd9Sstevel@tonic-gate } 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate static void 5047c478bd9Sstevel@tonic-gate optim_disable(struct aelist *h, int level) 5057c478bd9Sstevel@tonic-gate { 5067c478bd9Sstevel@tonic-gate if (level >= 2) { 5077c478bd9Sstevel@tonic-gate newae(h, "-fno-strict-aliasing"); 5087c478bd9Sstevel@tonic-gate newae(h, "-fno-unit-at-a-time"); 5097c478bd9Sstevel@tonic-gate newae(h, "-fno-optimize-sibling-calls"); 5107c478bd9Sstevel@tonic-gate } 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5147c478bd9Sstevel@tonic-gate static void 5157c478bd9Sstevel@tonic-gate Xamode(struct aelist *h) 5167c478bd9Sstevel@tonic-gate { 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate static void 5207c478bd9Sstevel@tonic-gate Xcmode(struct aelist *h) 5217c478bd9Sstevel@tonic-gate { 5227c478bd9Sstevel@tonic-gate static int xconce; 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate if (xconce++) 5257c478bd9Sstevel@tonic-gate return; 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate newae(h, "-ansi"); 5287c478bd9Sstevel@tonic-gate newae(h, "-pedantic-errors"); 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate static void 5327c478bd9Sstevel@tonic-gate Xsmode(struct aelist *h) 5337c478bd9Sstevel@tonic-gate { 5347c478bd9Sstevel@tonic-gate static int xsonce; 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate if (xsonce++) 5377c478bd9Sstevel@tonic-gate return; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate newae(h, "-traditional"); 5407c478bd9Sstevel@tonic-gate newae(h, "-traditional-cpp"); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate static void 5447c478bd9Sstevel@tonic-gate usage() 5457c478bd9Sstevel@tonic-gate { 5467c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 5477c478bd9Sstevel@tonic-gate "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n", 5487c478bd9Sstevel@tonic-gate progname); 5497c478bd9Sstevel@tonic-gate exit(2); 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate static void 5537c478bd9Sstevel@tonic-gate xlate(struct aelist *h, const char *xarg, const char **table) 5547c478bd9Sstevel@tonic-gate { 5557c478bd9Sstevel@tonic-gate while (*table != NULL && strcmp(xarg, *table) != 0) { 5567c478bd9Sstevel@tonic-gate while (*table != NULL) 5577c478bd9Sstevel@tonic-gate table++; 5587c478bd9Sstevel@tonic-gate table++; 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate if (*table == NULL) 5627c478bd9Sstevel@tonic-gate error(xarg); 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate table++; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate while (*table != NULL) { 5677c478bd9Sstevel@tonic-gate newae(h, *table); 5687c478bd9Sstevel@tonic-gate table++; 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate static void 573*80ab886dSwesolows do_gcc(cw_ictx_t *ctx) 5747c478bd9Sstevel@tonic-gate { 5757c478bd9Sstevel@tonic-gate int c; 576*80ab886dSwesolows int pic = 0, nolibc = 0; 577*80ab886dSwesolows int in_output = 0, seen_o = 0, c_files = 0; 578*80ab886dSwesolows cw_op_t op = CW_O_LINK; 5797c478bd9Sstevel@tonic-gate char *model = NULL; 5807c478bd9Sstevel@tonic-gate 581*80ab886dSwesolows newae(ctx->i_ae, "-fident"); 582*80ab886dSwesolows newae(ctx->i_ae, "-finline"); 583*80ab886dSwesolows newae(ctx->i_ae, "-fno-inline-functions"); 584*80ab886dSwesolows newae(ctx->i_ae, "-fno-builtin"); 585*80ab886dSwesolows newae(ctx->i_ae, "-fno-asm"); 586*80ab886dSwesolows newae(ctx->i_ae, "-nodefaultlibs"); 5877c478bd9Sstevel@tonic-gate 58802e56f3fSwesolows #if defined(__sparc) 58902e56f3fSwesolows /* 59002e56f3fSwesolows * The SPARC ldd and std instructions require 8-byte alignment of 59102e56f3fSwesolows * their address operand. gcc correctly uses them only when the 59202e56f3fSwesolows * ABI requires 8-byte alignment; unfortunately we have a number of 59302e56f3fSwesolows * pieces of buggy code that doesn't conform to the ABI. This 59402e56f3fSwesolows * flag makes gcc work more like Studio with -xmemalign=4. 59502e56f3fSwesolows */ 596*80ab886dSwesolows newae(ctx->i_ae, "-mno-integer-ldd-std"); 59702e56f3fSwesolows #endif 59802e56f3fSwesolows 5997c478bd9Sstevel@tonic-gate /* 6007c478bd9Sstevel@tonic-gate * This is needed because 'u' is defined 6017c478bd9Sstevel@tonic-gate * under a conditional on 'sun'. Should 6027c478bd9Sstevel@tonic-gate * probably just remove the conditional, 6037c478bd9Sstevel@tonic-gate * or make it be dependent on '__sun'. 6047c478bd9Sstevel@tonic-gate * 6057c478bd9Sstevel@tonic-gate * -Dunix is also missing in enhanced ANSI mode 6067c478bd9Sstevel@tonic-gate */ 607*80ab886dSwesolows newae(ctx->i_ae, "-D__sun"); 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate /* 6107c478bd9Sstevel@tonic-gate * Walk the argument list, translating as we go .. 6117c478bd9Sstevel@tonic-gate */ 6127c478bd9Sstevel@tonic-gate 613*80ab886dSwesolows while (--ctx->i_oldargc > 0) { 614*80ab886dSwesolows char *arg = *++ctx->i_oldargv; 6157c478bd9Sstevel@tonic-gate size_t arglen = strlen(arg); 6167c478bd9Sstevel@tonic-gate 617*80ab886dSwesolows if (*arg == '-') { 6187c478bd9Sstevel@tonic-gate arglen--; 619*80ab886dSwesolows } else { 6207c478bd9Sstevel@tonic-gate /* 6217c478bd9Sstevel@tonic-gate * Discard inline files that gcc doesn't grok 6227c478bd9Sstevel@tonic-gate */ 623*80ab886dSwesolows if (!in_output && arglen > 3 && 6247c478bd9Sstevel@tonic-gate strcmp(arg + arglen - 3, ".il") == 0) 6257c478bd9Sstevel@tonic-gate continue; 6267c478bd9Sstevel@tonic-gate 627*80ab886dSwesolows if (!in_output && arglen > 2 && 628*80ab886dSwesolows arg[arglen - 2] == '.' && 629*80ab886dSwesolows (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' || 630*80ab886dSwesolows arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i')) 631*80ab886dSwesolows c_files++; 632*80ab886dSwesolows 6337c478bd9Sstevel@tonic-gate /* 634*80ab886dSwesolows * Otherwise, filenames and partial arguments 635*80ab886dSwesolows * are passed through for gcc to chew on. However, 636*80ab886dSwesolows * output is always discarded for the secondary 637*80ab886dSwesolows * compiler. 6387c478bd9Sstevel@tonic-gate */ 639*80ab886dSwesolows if ((ctx->i_flags & CW_F_SHADOW) && in_output) 640*80ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 641*80ab886dSwesolows else 642*80ab886dSwesolows newae(ctx->i_ae, arg); 643*80ab886dSwesolows in_output = 0; 6447c478bd9Sstevel@tonic-gate continue; 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate 647*80ab886dSwesolows if (ctx->i_flags & CW_F_CXX) { 6487c478bd9Sstevel@tonic-gate if (strncmp(arg, "-compat=", 8) == 0) { 6497c478bd9Sstevel@tonic-gate /* discard -compat=4 and -compat=5 */ 6507c478bd9Sstevel@tonic-gate continue; 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Qoption") == 0) { 6537c478bd9Sstevel@tonic-gate /* discard -Qoption and its two arguments */ 654*80ab886dSwesolows if (ctx->i_oldargc < 3) 6557c478bd9Sstevel@tonic-gate error(arg); 656*80ab886dSwesolows ctx->i_oldargc -= 2; 657*80ab886dSwesolows ctx->i_oldargv += 2; 6587c478bd9Sstevel@tonic-gate continue; 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xwe") == 0) { 6617c478bd9Sstevel@tonic-gate /* turn warnings into errors */ 662*80ab886dSwesolows newae(ctx->i_ae, "-Werror"); 6637c478bd9Sstevel@tonic-gate continue; 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate if (strcmp(arg, "-noex") == 0) { 6667c478bd9Sstevel@tonic-gate /* no exceptions */ 667*80ab886dSwesolows newae(ctx->i_ae, "-fno-exceptions"); 6687c478bd9Sstevel@tonic-gate /* no run time type descriptor information */ 669*80ab886dSwesolows newae(ctx->i_ae, "-fno-rtti"); 6707c478bd9Sstevel@tonic-gate continue; 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate if (strcmp(arg, "-pic") == 0) { 673*80ab886dSwesolows newae(ctx->i_ae, "-fpic"); 6747c478bd9Sstevel@tonic-gate pic = 1; 6757c478bd9Sstevel@tonic-gate continue; 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate if (strcmp(arg, "-PIC") == 0) { 678*80ab886dSwesolows newae(ctx->i_ae, "-fPIC"); 6797c478bd9Sstevel@tonic-gate pic = 1; 6807c478bd9Sstevel@tonic-gate continue; 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate if (strcmp(arg, "-norunpath") == 0) { 6837c478bd9Sstevel@tonic-gate /* gcc has no corresponding option */ 6847c478bd9Sstevel@tonic-gate continue; 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate if (strcmp(arg, "-nolib") == 0) { 6877c478bd9Sstevel@tonic-gate /* -nodefaultlibs is on by default */ 6887c478bd9Sstevel@tonic-gate nolibc = 1; 6897c478bd9Sstevel@tonic-gate continue; 6907c478bd9Sstevel@tonic-gate } 6917c478bd9Sstevel@tonic-gate #if defined(__sparc) 6927c478bd9Sstevel@tonic-gate if (strcmp(arg, "-cg92") == 0) { 693*80ab886dSwesolows xlate(ctx->i_ae, "v8", xarch_tbl); 694*80ab886dSwesolows xlate(ctx->i_ae, "super", xchip_tbl); 6957c478bd9Sstevel@tonic-gate continue; 6967c478bd9Sstevel@tonic-gate } 6977c478bd9Sstevel@tonic-gate #endif /* __sparc */ 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate switch ((c = arg[1])) { 7017c478bd9Sstevel@tonic-gate case '_': 7027c478bd9Sstevel@tonic-gate if (strcmp(arg, "-_noecho") == 0) 703*80ab886dSwesolows ctx->i_flags &= ~CW_F_ECHO; 7047c478bd9Sstevel@tonic-gate else if (strncmp(arg, "-_cc=", 5) == 0 || 7057c478bd9Sstevel@tonic-gate strncmp(arg, "-_CC=", 5) == 0) 7067c478bd9Sstevel@tonic-gate /* EMPTY */; 7077c478bd9Sstevel@tonic-gate else if (strncmp(arg, "-_gcc=", 6) == 0 || 7087c478bd9Sstevel@tonic-gate strncmp(arg, "-_g++=", 6) == 0) 709*80ab886dSwesolows newae(ctx->i_ae, arg + 6); 710*80ab886dSwesolows else 7117c478bd9Sstevel@tonic-gate error(arg); 7127c478bd9Sstevel@tonic-gate break; 7137c478bd9Sstevel@tonic-gate case '#': 7147c478bd9Sstevel@tonic-gate if (arglen == 1) { 715*80ab886dSwesolows newae(ctx->i_ae, "-v"); 7167c478bd9Sstevel@tonic-gate break; 7177c478bd9Sstevel@tonic-gate } 7187c478bd9Sstevel@tonic-gate error(arg); 7197c478bd9Sstevel@tonic-gate break; 7207c478bd9Sstevel@tonic-gate case 'g': 721*80ab886dSwesolows newae(ctx->i_ae, "-gdwarf-2"); 7227c478bd9Sstevel@tonic-gate break; 7237c478bd9Sstevel@tonic-gate case 'E': 7247c478bd9Sstevel@tonic-gate if (arglen == 1) { 725*80ab886dSwesolows newae(ctx->i_ae, "-xc"); 726*80ab886dSwesolows newae(ctx->i_ae, arg); 727*80ab886dSwesolows op = CW_O_PREPROCESS; 7287c478bd9Sstevel@tonic-gate nolibc = 1; 7297c478bd9Sstevel@tonic-gate break; 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate error(arg); 7327c478bd9Sstevel@tonic-gate break; 7337c478bd9Sstevel@tonic-gate case 'c': 7347c478bd9Sstevel@tonic-gate case 'S': 735*80ab886dSwesolows if (arglen == 1) { 736*80ab886dSwesolows op = CW_O_COMPILE; 7377c478bd9Sstevel@tonic-gate nolibc = 1; 738*80ab886dSwesolows } 7397c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 7407c478bd9Sstevel@tonic-gate case 'C': 7417c478bd9Sstevel@tonic-gate case 'H': 7427c478bd9Sstevel@tonic-gate case 'p': 7437c478bd9Sstevel@tonic-gate if (arglen == 1) { 744*80ab886dSwesolows newae(ctx->i_ae, arg); 7457c478bd9Sstevel@tonic-gate break; 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate error(arg); 7487c478bd9Sstevel@tonic-gate break; 7497c478bd9Sstevel@tonic-gate case 'A': 7507c478bd9Sstevel@tonic-gate case 'h': 7517c478bd9Sstevel@tonic-gate case 'I': 7527c478bd9Sstevel@tonic-gate case 'i': 7537c478bd9Sstevel@tonic-gate case 'L': 7547c478bd9Sstevel@tonic-gate case 'l': 7557c478bd9Sstevel@tonic-gate case 'R': 7567c478bd9Sstevel@tonic-gate case 'U': 7577c478bd9Sstevel@tonic-gate case 'u': 7587c478bd9Sstevel@tonic-gate case 'w': 759*80ab886dSwesolows newae(ctx->i_ae, arg); 760*80ab886dSwesolows break; 761*80ab886dSwesolows case 'o': 762*80ab886dSwesolows seen_o = 1; 763*80ab886dSwesolows if (arglen == 1) { 764*80ab886dSwesolows in_output = 1; 765*80ab886dSwesolows newae(ctx->i_ae, arg); 766*80ab886dSwesolows } else if (ctx->i_flags & CW_F_SHADOW) { 767*80ab886dSwesolows newae(ctx->i_ae, "-o"); 768*80ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 769*80ab886dSwesolows } else { 770*80ab886dSwesolows newae(ctx->i_ae, arg); 771*80ab886dSwesolows } 7727c478bd9Sstevel@tonic-gate break; 7737c478bd9Sstevel@tonic-gate case 'D': 774*80ab886dSwesolows newae(ctx->i_ae, arg); 7757c478bd9Sstevel@tonic-gate /* 7767c478bd9Sstevel@tonic-gate * XXX Clearly a hack ... do we need _KADB too? 7777c478bd9Sstevel@tonic-gate */ 7787c478bd9Sstevel@tonic-gate if (strcmp(arg, "-D_KERNEL") == 0 || 7797c478bd9Sstevel@tonic-gate strcmp(arg, "-D_BOOT") == 0) 780*80ab886dSwesolows newae(ctx->i_ae, "-ffreestanding"); 7817c478bd9Sstevel@tonic-gate break; 7827c478bd9Sstevel@tonic-gate case 'd': 7837c478bd9Sstevel@tonic-gate if (arglen == 2) { 7847c478bd9Sstevel@tonic-gate if (strcmp(arg, "-dy") == 0) { 785*80ab886dSwesolows newae(ctx->i_ae, "-Wl,-dy"); 7867c478bd9Sstevel@tonic-gate break; 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate if (strcmp(arg, "-dn") == 0) { 789*80ab886dSwesolows newae(ctx->i_ae, "-Wl,-dn"); 7907c478bd9Sstevel@tonic-gate break; 7917c478bd9Sstevel@tonic-gate } 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate if (strcmp(arg, "-dalign") == 0) { 7947c478bd9Sstevel@tonic-gate /* 7957c478bd9Sstevel@tonic-gate * -dalign forces alignment in some cases; 7967c478bd9Sstevel@tonic-gate * gcc does not need any flag to do this. 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate break; 7997c478bd9Sstevel@tonic-gate } 8007c478bd9Sstevel@tonic-gate error(arg); 8017c478bd9Sstevel@tonic-gate break; 8027c478bd9Sstevel@tonic-gate case 'e': 8037c478bd9Sstevel@tonic-gate if (strcmp(arg, 8047c478bd9Sstevel@tonic-gate "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) { 8057c478bd9Sstevel@tonic-gate /* 8067c478bd9Sstevel@tonic-gate * Accept but ignore this -- gcc doesn't 8077c478bd9Sstevel@tonic-gate * seem to complain about empty translation 8087c478bd9Sstevel@tonic-gate * units 8097c478bd9Sstevel@tonic-gate */ 8107c478bd9Sstevel@tonic-gate break; 8117c478bd9Sstevel@tonic-gate } 8127c478bd9Sstevel@tonic-gate /* XX64 -- ignore all -erroff= options, for now */ 8137c478bd9Sstevel@tonic-gate if (strncmp(arg, "-erroff=", 8) == 0) 8147c478bd9Sstevel@tonic-gate break; 8157c478bd9Sstevel@tonic-gate if (strcmp(arg, "-errtags=yes") == 0) { 816*80ab886dSwesolows warnings(ctx->i_ae); 8177c478bd9Sstevel@tonic-gate break; 8187c478bd9Sstevel@tonic-gate } 8197c478bd9Sstevel@tonic-gate if (strcmp(arg, "-errwarn=%all") == 0) { 820*80ab886dSwesolows newae(ctx->i_ae, "-Werror"); 8217c478bd9Sstevel@tonic-gate break; 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate error(arg); 8247c478bd9Sstevel@tonic-gate break; 8257c478bd9Sstevel@tonic-gate case 'f': 8267c478bd9Sstevel@tonic-gate if (strcmp(arg, "-flags") == 0) { 827*80ab886dSwesolows newae(ctx->i_ae, "--help"); 8287c478bd9Sstevel@tonic-gate break; 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate error(arg); 8317c478bd9Sstevel@tonic-gate break; 8327c478bd9Sstevel@tonic-gate case 'G': 833*80ab886dSwesolows newae(ctx->i_ae, "-shared"); 8347c478bd9Sstevel@tonic-gate nolibc = 1; 8357c478bd9Sstevel@tonic-gate break; 8367c478bd9Sstevel@tonic-gate case 'k': 8377c478bd9Sstevel@tonic-gate if (strcmp(arg, "-keeptmp") == 0) { 838*80ab886dSwesolows newae(ctx->i_ae, "-save-temps"); 8397c478bd9Sstevel@tonic-gate break; 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate error(arg); 8427c478bd9Sstevel@tonic-gate break; 8437c478bd9Sstevel@tonic-gate case 'K': 8447c478bd9Sstevel@tonic-gate if (arglen == 1) { 845*80ab886dSwesolows if ((arg = *++ctx->i_oldargv) == NULL || 846*80ab886dSwesolows *arg == '\0') 8477c478bd9Sstevel@tonic-gate error("-K"); 848*80ab886dSwesolows ctx->i_oldargc--; 8497c478bd9Sstevel@tonic-gate } else { 8507c478bd9Sstevel@tonic-gate arg += 2; 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate if (strcmp(arg, "pic") == 0) { 853*80ab886dSwesolows newae(ctx->i_ae, "-fpic"); 8547c478bd9Sstevel@tonic-gate pic = 1; 8557c478bd9Sstevel@tonic-gate break; 8567c478bd9Sstevel@tonic-gate } 8577c478bd9Sstevel@tonic-gate if (strcmp(arg, "PIC") == 0) { 858*80ab886dSwesolows newae(ctx->i_ae, "-fPIC"); 8597c478bd9Sstevel@tonic-gate pic = 1; 8607c478bd9Sstevel@tonic-gate break; 8617c478bd9Sstevel@tonic-gate } 8627c478bd9Sstevel@tonic-gate error("-K"); 8637c478bd9Sstevel@tonic-gate break; 8647c478bd9Sstevel@tonic-gate case 'm': 8657c478bd9Sstevel@tonic-gate if (strcmp(arg, "-mt") == 0) { 866*80ab886dSwesolows newae(ctx->i_ae, "-D_REENTRANT"); 8677c478bd9Sstevel@tonic-gate break; 8687c478bd9Sstevel@tonic-gate } 8697c478bd9Sstevel@tonic-gate error(arg); 8707c478bd9Sstevel@tonic-gate break; 8717c478bd9Sstevel@tonic-gate case 'B': /* linker options */ 8727c478bd9Sstevel@tonic-gate case 'M': 8737c478bd9Sstevel@tonic-gate case 'z': 8747c478bd9Sstevel@tonic-gate { 8757c478bd9Sstevel@tonic-gate char *opt; 8767c478bd9Sstevel@tonic-gate size_t len; 8777c478bd9Sstevel@tonic-gate char *s; 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate if (arglen == 1) { 880*80ab886dSwesolows opt = *++ctx->i_oldargv; 8817c478bd9Sstevel@tonic-gate if (opt == NULL || *opt == '\0') 8827c478bd9Sstevel@tonic-gate error(arg); 883*80ab886dSwesolows ctx->i_oldargc--; 8847c478bd9Sstevel@tonic-gate } else { 8857c478bd9Sstevel@tonic-gate opt = arg + 2; 8867c478bd9Sstevel@tonic-gate } 8877c478bd9Sstevel@tonic-gate len = strlen(opt) + 7; 888*80ab886dSwesolows if ((s = malloc(len)) == NULL) 889*80ab886dSwesolows nomem(); 8907c478bd9Sstevel@tonic-gate (void) snprintf(s, len, "-Wl,-%c%s", c, opt); 891*80ab886dSwesolows newae(ctx->i_ae, s); 8927c478bd9Sstevel@tonic-gate free(s); 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate break; 8957c478bd9Sstevel@tonic-gate case 'n': 8967c478bd9Sstevel@tonic-gate if (strcmp(arg, "-noqueue") == 0) { 8977c478bd9Sstevel@tonic-gate /* 8987c478bd9Sstevel@tonic-gate * Horrid license server stuff - n/a 8997c478bd9Sstevel@tonic-gate */ 9007c478bd9Sstevel@tonic-gate break; 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate error(arg); 9037c478bd9Sstevel@tonic-gate break; 9047c478bd9Sstevel@tonic-gate case 'O': 9057c478bd9Sstevel@tonic-gate if (arglen == 1) { 906*80ab886dSwesolows newae(ctx->i_ae, "-O"); 9077c478bd9Sstevel@tonic-gate break; 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate error(arg); 9107c478bd9Sstevel@tonic-gate break; 9117c478bd9Sstevel@tonic-gate case 'P': 9127c478bd9Sstevel@tonic-gate /* 9137c478bd9Sstevel@tonic-gate * We could do '-E -o filename.i', but that's hard, 9147c478bd9Sstevel@tonic-gate * and we don't need it for the case that's triggering 9157c478bd9Sstevel@tonic-gate * this addition. We'll require the user to specify 9167c478bd9Sstevel@tonic-gate * -o in the Makefile. If they don't they'll find out 9177c478bd9Sstevel@tonic-gate * in a hurry. 9187c478bd9Sstevel@tonic-gate */ 919*80ab886dSwesolows newae(ctx->i_ae, "-E"); 920*80ab886dSwesolows op = CW_O_PREPROCESS; 9217c478bd9Sstevel@tonic-gate nolibc = 1; 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate case 'q': 9247c478bd9Sstevel@tonic-gate if (strcmp(arg, "-qp") == 0) { 925*80ab886dSwesolows newae(ctx->i_ae, "-p"); 9267c478bd9Sstevel@tonic-gate break; 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate error(arg); 9297c478bd9Sstevel@tonic-gate break; 9307c478bd9Sstevel@tonic-gate case 's': 9317c478bd9Sstevel@tonic-gate if (arglen == 1) { 932*80ab886dSwesolows newae(ctx->i_ae, "-Wl,-s"); 9337c478bd9Sstevel@tonic-gate break; 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate error(arg); 9367c478bd9Sstevel@tonic-gate break; 937159cf8a6Swesolows case 't': 938159cf8a6Swesolows if (arglen == 1) { 939*80ab886dSwesolows newae(ctx->i_ae, "-Wl,-t"); 940159cf8a6Swesolows break; 941159cf8a6Swesolows } 942159cf8a6Swesolows error(arg); 943159cf8a6Swesolows break; 9447c478bd9Sstevel@tonic-gate case 'V': 9457c478bd9Sstevel@tonic-gate if (arglen == 1) { 946*80ab886dSwesolows ctx->i_flags &= ~CW_F_ECHO; 947*80ab886dSwesolows newae(ctx->i_ae, "--version"); 9487c478bd9Sstevel@tonic-gate break; 9497c478bd9Sstevel@tonic-gate } 9507c478bd9Sstevel@tonic-gate error(arg); 9517c478bd9Sstevel@tonic-gate break; 9527c478bd9Sstevel@tonic-gate case 'v': 9537c478bd9Sstevel@tonic-gate if (arglen == 1) { 954*80ab886dSwesolows warnings(ctx->i_ae); 9557c478bd9Sstevel@tonic-gate break; 9567c478bd9Sstevel@tonic-gate } 9577c478bd9Sstevel@tonic-gate error(arg); 9587c478bd9Sstevel@tonic-gate break; 9597c478bd9Sstevel@tonic-gate case 'W': 9607c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wp,-xc99", 9) == 0) { 9617c478bd9Sstevel@tonic-gate /* 9627c478bd9Sstevel@tonic-gate * gcc's preprocessor will accept c99 9637c478bd9Sstevel@tonic-gate * regardless, so accept and ignore. 9647c478bd9Sstevel@tonic-gate */ 9657c478bd9Sstevel@tonic-gate break; 9667c478bd9Sstevel@tonic-gate } 9677c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wa,", 4) == 0 || 9687c478bd9Sstevel@tonic-gate strncmp(arg, "-Wp,", 4) == 0 || 9697c478bd9Sstevel@tonic-gate strncmp(arg, "-Wl,", 4) == 0) { 970*80ab886dSwesolows newae(ctx->i_ae, arg); 9717c478bd9Sstevel@tonic-gate break; 9727c478bd9Sstevel@tonic-gate } 9737c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-xc99=pragma") == 0) { 9747c478bd9Sstevel@tonic-gate /* (undocumented) enables _Pragma */ 9757c478bd9Sstevel@tonic-gate break; 9767c478bd9Sstevel@tonic-gate } 9777c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-xc99=%none") == 0) { 9787c478bd9Sstevel@tonic-gate /* 9797c478bd9Sstevel@tonic-gate * This is a polite way of saying 9807c478bd9Sstevel@tonic-gate * "no c99 constructs allowed!" 9817c478bd9Sstevel@tonic-gate * For now, just accept and ignore this. 9827c478bd9Sstevel@tonic-gate */ 9837c478bd9Sstevel@tonic-gate break; 9847c478bd9Sstevel@tonic-gate } 9857c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-noglobal") == 0) { 9867c478bd9Sstevel@tonic-gate /* 9877c478bd9Sstevel@tonic-gate * gcc doesn't prefix local symbols 9887c478bd9Sstevel@tonic-gate * in debug mode, so this is not needed. 9897c478bd9Sstevel@tonic-gate */ 9907c478bd9Sstevel@tonic-gate break; 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-Lt") == 0) { 9937c478bd9Sstevel@tonic-gate /* 9947c478bd9Sstevel@tonic-gate * Generate tests at the top of loops. 9957c478bd9Sstevel@tonic-gate * There is no direct gcc equivalent, ignore. 9967c478bd9Sstevel@tonic-gate */ 9977c478bd9Sstevel@tonic-gate break; 9987c478bd9Sstevel@tonic-gate } 9998c1a3716Ssherrym if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) { 1000*80ab886dSwesolows newae(ctx->i_ae, 1001*80ab886dSwesolows "-fno-eliminate-unused-debug-symbols"); 1002*80ab886dSwesolows newae(ctx->i_ae, 1003*80ab886dSwesolows "-fno-eliminate-unused-debug-types"); 10048c1a3716Ssherrym break; 10058c1a3716Ssherrym } 10067c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W2,-Rcond_elim") == 0) { 10077c478bd9Sstevel@tonic-gate /* 10087c478bd9Sstevel@tonic-gate * Elimination and expansion of conditionals; 10097c478bd9Sstevel@tonic-gate * gcc has no direct equivalent. 10107c478bd9Sstevel@tonic-gate */ 10117c478bd9Sstevel@tonic-gate break; 10127c478bd9Sstevel@tonic-gate } 10137c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) { 10147c478bd9Sstevel@tonic-gate /* 10157c478bd9Sstevel@tonic-gate * Prevents optimizing away checks for 10167c478bd9Sstevel@tonic-gate * unbound weak symbol addresses. gcc does 10177c478bd9Sstevel@tonic-gate * not do this, so it's not needed. 10187c478bd9Sstevel@tonic-gate */ 10197c478bd9Sstevel@tonic-gate break; 10207c478bd9Sstevel@tonic-gate } 10217c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wc,-xcode=", 11) == 0) { 1022*80ab886dSwesolows xlate(ctx->i_ae, arg + 11, xcode_tbl); 10237c478bd9Sstevel@tonic-gate if (strncmp(arg + 11, "pic", 3) == 0) 10247c478bd9Sstevel@tonic-gate pic = 1; 10257c478bd9Sstevel@tonic-gate break; 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) { 10287c478bd9Sstevel@tonic-gate /* 10297c478bd9Sstevel@tonic-gate * Prevents insertion of register symbols. 10307c478bd9Sstevel@tonic-gate * gcc doesn't do this, so ignore it. 10317c478bd9Sstevel@tonic-gate */ 10327c478bd9Sstevel@tonic-gate break; 10337c478bd9Sstevel@tonic-gate } 10347c478bd9Sstevel@tonic-gate #if defined(__x86) 10357c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Wu,-no_got_reloc") == 0) { 1036*80ab886dSwesolows newae(ctx->i_ae, "-fno-jump-tables"); 1037*80ab886dSwesolows newae(ctx->i_ae, "-fno-constant-pools"); 10387c478bd9Sstevel@tonic-gate break; 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) { 1041*80ab886dSwesolows newae(ctx->i_ae, "-ffreestanding"); 1042*80ab886dSwesolows newae(ctx->i_ae, "-mno-red-zone"); 10437c478bd9Sstevel@tonic-gate model = "-mcmodel=kernel"; 10447c478bd9Sstevel@tonic-gate nolibc = 1; 10457c478bd9Sstevel@tonic-gate break; 10467c478bd9Sstevel@tonic-gate } 1047d430274bSsherrym if (strcmp(arg, "-Wu,-save_args") == 0) { 1048*80ab886dSwesolows newae(ctx->i_ae, "-msave-args"); 1049d430274bSsherrym break; 1050d430274bSsherrym } 10517c478bd9Sstevel@tonic-gate #endif /* __x86 */ 10527c478bd9Sstevel@tonic-gate error(arg); 10537c478bd9Sstevel@tonic-gate break; 10547c478bd9Sstevel@tonic-gate case 'X': 10557c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Xa") == 0 || 10567c478bd9Sstevel@tonic-gate strcmp(arg, "-Xt") == 0) { 1057*80ab886dSwesolows Xamode(ctx->i_ae); 10587c478bd9Sstevel@tonic-gate break; 10597c478bd9Sstevel@tonic-gate } 10607c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Xc") == 0) { 1061*80ab886dSwesolows Xcmode(ctx->i_ae); 10627c478bd9Sstevel@tonic-gate break; 10637c478bd9Sstevel@tonic-gate } 10647c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Xs") == 0) { 1065*80ab886dSwesolows Xsmode(ctx->i_ae); 10667c478bd9Sstevel@tonic-gate break; 10677c478bd9Sstevel@tonic-gate } 10687c478bd9Sstevel@tonic-gate error(arg); 10697c478bd9Sstevel@tonic-gate break; 10707c478bd9Sstevel@tonic-gate case 'x': 10717c478bd9Sstevel@tonic-gate if (arglen == 1) 10727c478bd9Sstevel@tonic-gate error(arg); 10737c478bd9Sstevel@tonic-gate switch (arg[2]) { 10747c478bd9Sstevel@tonic-gate #if defined(__x86) 10757c478bd9Sstevel@tonic-gate case '3': 10767c478bd9Sstevel@tonic-gate if (strcmp(arg, "-x386") == 0) { 1077*80ab886dSwesolows newae(ctx->i_ae, "-march=i386"); 10787c478bd9Sstevel@tonic-gate break; 10797c478bd9Sstevel@tonic-gate } 10807c478bd9Sstevel@tonic-gate error(arg); 10817c478bd9Sstevel@tonic-gate break; 10827c478bd9Sstevel@tonic-gate case '4': 10837c478bd9Sstevel@tonic-gate if (strcmp(arg, "-x486") == 0) { 1084*80ab886dSwesolows newae(ctx->i_ae, "-march=i486"); 10857c478bd9Sstevel@tonic-gate break; 10867c478bd9Sstevel@tonic-gate } 10877c478bd9Sstevel@tonic-gate error(arg); 10887c478bd9Sstevel@tonic-gate break; 10897c478bd9Sstevel@tonic-gate #endif /* __x86 */ 10907c478bd9Sstevel@tonic-gate case 'a': 10917c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xarch=", 7) == 0) { 1092*80ab886dSwesolows xlate(ctx->i_ae, arg + 7, xarch_tbl); 10937c478bd9Sstevel@tonic-gate break; 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate error(arg); 10967c478bd9Sstevel@tonic-gate break; 109702e56f3fSwesolows case 'b': 109802e56f3fSwesolows if (strncmp(arg, "-xbuiltin=", 10) == 0) { 109902e56f3fSwesolows if (strcmp(arg + 10, "%all")) 1100*80ab886dSwesolows newae(ctx->i_ae, "-fbuiltin"); 110102e56f3fSwesolows break; 110202e56f3fSwesolows } 110302e56f3fSwesolows error(arg); 110402e56f3fSwesolows break; 11057c478bd9Sstevel@tonic-gate case 'C': 11067c478bd9Sstevel@tonic-gate /* Accept C++ style comments -- ignore */ 11077c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xCC") == 0) 11087c478bd9Sstevel@tonic-gate break; 11097c478bd9Sstevel@tonic-gate error(arg); 11107c478bd9Sstevel@tonic-gate break; 11117c478bd9Sstevel@tonic-gate case 'c': 11127c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xc99=%all", 10) == 0) { 1113*80ab886dSwesolows newae(ctx->i_ae, "-std=gnu99"); 11147c478bd9Sstevel@tonic-gate break; 11157c478bd9Sstevel@tonic-gate } 11167c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xc99=%none", 11) == 0) { 1117*80ab886dSwesolows newae(ctx->i_ae, "-std=gnu89"); 11187c478bd9Sstevel@tonic-gate break; 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xchip=", 7) == 0) { 1121*80ab886dSwesolows xlate(ctx->i_ae, arg + 7, xchip_tbl); 11227c478bd9Sstevel@tonic-gate break; 11237c478bd9Sstevel@tonic-gate } 11247c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xcode=", 7) == 0) { 1125*80ab886dSwesolows xlate(ctx->i_ae, arg + 7, xcode_tbl); 11267c478bd9Sstevel@tonic-gate if (strncmp(arg + 7, "pic", 3) == 0) 11277c478bd9Sstevel@tonic-gate pic = 1; 11287c478bd9Sstevel@tonic-gate break; 11297c478bd9Sstevel@tonic-gate } 11307c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xcache=", 8) == 0) 11317c478bd9Sstevel@tonic-gate break; 1132159cf8a6Swesolows if (strncmp(arg, "-xcrossfile", 11) == 0) 1133159cf8a6Swesolows break; 11347c478bd9Sstevel@tonic-gate error(arg); 11357c478bd9Sstevel@tonic-gate break; 11367c478bd9Sstevel@tonic-gate case 'd': 11377c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xdepend") == 0) 11387c478bd9Sstevel@tonic-gate break; 11398c1a3716Ssherrym if (strncmp(arg, "-xdebugformat=", 14) == 0) 11408c1a3716Ssherrym break; 11417c478bd9Sstevel@tonic-gate error(arg); 11427c478bd9Sstevel@tonic-gate break; 11437c478bd9Sstevel@tonic-gate case 'F': 11447c478bd9Sstevel@tonic-gate /* compile for mapfile reordering -- ignore */ 11457c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xF") == 0) 11467c478bd9Sstevel@tonic-gate break; 11477c478bd9Sstevel@tonic-gate error(arg); 11487c478bd9Sstevel@tonic-gate break; 11497c478bd9Sstevel@tonic-gate case 'i': 11507c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xinline", 8) == 0) 11517c478bd9Sstevel@tonic-gate /* No inlining; ignore */ 11527c478bd9Sstevel@tonic-gate break; 11537c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xildon") == 0 || 11547c478bd9Sstevel@tonic-gate strcmp(arg, "-xildoff") == 0) 11557c478bd9Sstevel@tonic-gate /* No incremental linking; ignore */ 11567c478bd9Sstevel@tonic-gate break; 11577c478bd9Sstevel@tonic-gate error(arg); 11587c478bd9Sstevel@tonic-gate break; 11597c478bd9Sstevel@tonic-gate case 'M': 11607c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xM") == 0) { 1161*80ab886dSwesolows newae(ctx->i_ae, "-M"); 11627c478bd9Sstevel@tonic-gate break; 11637c478bd9Sstevel@tonic-gate } 11647c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xM1") == 0) { 1165*80ab886dSwesolows newae(ctx->i_ae, "-MM"); 11667c478bd9Sstevel@tonic-gate break; 11677c478bd9Sstevel@tonic-gate } 11687c478bd9Sstevel@tonic-gate error(arg); 11697c478bd9Sstevel@tonic-gate break; 11707c478bd9Sstevel@tonic-gate case 'n': 11717c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xnolib") == 0) { 11727c478bd9Sstevel@tonic-gate nolibc = 1; 11737c478bd9Sstevel@tonic-gate break; 11747c478bd9Sstevel@tonic-gate } 11757c478bd9Sstevel@tonic-gate error(arg); 11767c478bd9Sstevel@tonic-gate break; 11777c478bd9Sstevel@tonic-gate case 'O': 11787c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xO", 3) == 0) { 11797c478bd9Sstevel@tonic-gate size_t len = strlen(arg); 1180*80ab886dSwesolows char *s; 11817c478bd9Sstevel@tonic-gate int c = *(arg + 3); 11827c478bd9Sstevel@tonic-gate int level; 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate if (len != 4 || !isdigit(c)) 11857c478bd9Sstevel@tonic-gate error(arg); 11867c478bd9Sstevel@tonic-gate 1187*80ab886dSwesolows if ((s = malloc(len)) == NULL) 1188*80ab886dSwesolows nomem(); 1189*80ab886dSwesolows 11907c478bd9Sstevel@tonic-gate level = atoi(arg + 3); 11917c478bd9Sstevel@tonic-gate if (level > 5) 11927c478bd9Sstevel@tonic-gate error(arg); 11937c478bd9Sstevel@tonic-gate if (level >= 2) { 11947c478bd9Sstevel@tonic-gate /* 11957c478bd9Sstevel@tonic-gate * For gcc-3.4.x at -O2 we 11967c478bd9Sstevel@tonic-gate * need to disable optimizations 11977c478bd9Sstevel@tonic-gate * that break ON. 11987c478bd9Sstevel@tonic-gate */ 1199*80ab886dSwesolows optim_disable(ctx->i_ae, level); 12007c478bd9Sstevel@tonic-gate /* 12017c478bd9Sstevel@tonic-gate * limit -xO3 to -O2 as well. 12027c478bd9Sstevel@tonic-gate */ 12037c478bd9Sstevel@tonic-gate level = 2; 12047c478bd9Sstevel@tonic-gate } 12057c478bd9Sstevel@tonic-gate (void) snprintf(s, len, "-O%d", level); 1206*80ab886dSwesolows newae(ctx->i_ae, s); 12077c478bd9Sstevel@tonic-gate free(s); 12087c478bd9Sstevel@tonic-gate break; 12097c478bd9Sstevel@tonic-gate } 12107c478bd9Sstevel@tonic-gate error(arg); 12117c478bd9Sstevel@tonic-gate break; 12127c478bd9Sstevel@tonic-gate case 'p': 12137c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xpentium") == 0) { 1214*80ab886dSwesolows newae(ctx->i_ae, "-march=pentium"); 12157c478bd9Sstevel@tonic-gate break; 12167c478bd9Sstevel@tonic-gate } 12177c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xpg") == 0) { 1218*80ab886dSwesolows newae(ctx->i_ae, "-pg"); 12197c478bd9Sstevel@tonic-gate break; 12207c478bd9Sstevel@tonic-gate } 12217c478bd9Sstevel@tonic-gate error(arg); 12227c478bd9Sstevel@tonic-gate break; 12237c478bd9Sstevel@tonic-gate case 'r': 12247c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xregs=", 7) == 0) { 1225*80ab886dSwesolows xlate(ctx->i_ae, arg + 7, xregs_tbl); 12267c478bd9Sstevel@tonic-gate break; 12277c478bd9Sstevel@tonic-gate } 12287c478bd9Sstevel@tonic-gate error(arg); 12297c478bd9Sstevel@tonic-gate break; 12307c478bd9Sstevel@tonic-gate case 's': 12317c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xs") == 0 || 12327c478bd9Sstevel@tonic-gate strcmp(arg, "-xspace") == 0 || 12337c478bd9Sstevel@tonic-gate strcmp(arg, "-xstrconst") == 0) 12347c478bd9Sstevel@tonic-gate break; 12357c478bd9Sstevel@tonic-gate error(arg); 12367c478bd9Sstevel@tonic-gate break; 12377c478bd9Sstevel@tonic-gate case 't': 12387c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xtransition") == 0) { 1239*80ab886dSwesolows newae(ctx->i_ae, "-Wtransition"); 12407c478bd9Sstevel@tonic-gate break; 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xtrigraphs=yes") == 0) { 1243*80ab886dSwesolows newae(ctx->i_ae, "-trigraphs"); 12447c478bd9Sstevel@tonic-gate break; 12457c478bd9Sstevel@tonic-gate } 12467c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xtrigraphs=no") == 0) { 1247*80ab886dSwesolows newae(ctx->i_ae, "-notrigraphs"); 12487c478bd9Sstevel@tonic-gate break; 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xtarget=", 9) == 0) { 1251*80ab886dSwesolows xlate(ctx->i_ae, arg + 9, xtarget_tbl); 12527c478bd9Sstevel@tonic-gate break; 12537c478bd9Sstevel@tonic-gate } 12547c478bd9Sstevel@tonic-gate error(arg); 12557c478bd9Sstevel@tonic-gate break; 12567c478bd9Sstevel@tonic-gate case 'e': 12577c478bd9Sstevel@tonic-gate case 'h': 12587c478bd9Sstevel@tonic-gate case 'l': 12597c478bd9Sstevel@tonic-gate default: 12607c478bd9Sstevel@tonic-gate error(arg); 12617c478bd9Sstevel@tonic-gate break; 12627c478bd9Sstevel@tonic-gate } 12637c478bd9Sstevel@tonic-gate break; 12647c478bd9Sstevel@tonic-gate case 'Y': 12657c478bd9Sstevel@tonic-gate if (arglen == 1) { 1266*80ab886dSwesolows if ((arg = *++ctx->i_oldargv) == NULL || 1267*80ab886dSwesolows *arg == '\0') 12687c478bd9Sstevel@tonic-gate error("-Y"); 1269*80ab886dSwesolows ctx->i_oldargc--; 12707c478bd9Sstevel@tonic-gate arglen = strlen(arg + 1); 12717c478bd9Sstevel@tonic-gate } else { 12727c478bd9Sstevel@tonic-gate arg += 2; 12737c478bd9Sstevel@tonic-gate } 12747c478bd9Sstevel@tonic-gate /* Just ignore -YS,... for now */ 12757c478bd9Sstevel@tonic-gate if (strncmp(arg, "S,", 2) == 0) 12767c478bd9Sstevel@tonic-gate break; 12777c478bd9Sstevel@tonic-gate if (strncmp(arg, "l,", 2) == 0) { 12787c478bd9Sstevel@tonic-gate char *s = strdup(arg); 12797c478bd9Sstevel@tonic-gate s[0] = '-'; 12807c478bd9Sstevel@tonic-gate s[1] = 'B'; 1281*80ab886dSwesolows newae(ctx->i_ae, s); 12827c478bd9Sstevel@tonic-gate free(s); 12837c478bd9Sstevel@tonic-gate break; 12847c478bd9Sstevel@tonic-gate } 12857c478bd9Sstevel@tonic-gate if (strncmp(arg, "I,", 2) == 0) { 12867c478bd9Sstevel@tonic-gate char *s = strdup(arg); 12877c478bd9Sstevel@tonic-gate s[0] = '-'; 12887c478bd9Sstevel@tonic-gate s[1] = 'I'; 1289*80ab886dSwesolows newae(ctx->i_ae, "-nostdinc"); 1290*80ab886dSwesolows newae(ctx->i_ae, s); 12917c478bd9Sstevel@tonic-gate free(s); 12927c478bd9Sstevel@tonic-gate break; 12937c478bd9Sstevel@tonic-gate } 12947c478bd9Sstevel@tonic-gate error(arg); 12957c478bd9Sstevel@tonic-gate break; 12967c478bd9Sstevel@tonic-gate case 'Q': 12977c478bd9Sstevel@tonic-gate /* 12987c478bd9Sstevel@tonic-gate * We could map -Qy into -Wl,-Qy etc. 12997c478bd9Sstevel@tonic-gate */ 13007c478bd9Sstevel@tonic-gate default: 13017c478bd9Sstevel@tonic-gate error(arg); 13027c478bd9Sstevel@tonic-gate break; 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate } 13057c478bd9Sstevel@tonic-gate 1306*80ab886dSwesolows if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) && 1307*80ab886dSwesolows op != CW_O_PREPROCESS) { 1308*80ab886dSwesolows (void) fprintf(stderr, "%s: error: multiple source files are " 1309*80ab886dSwesolows "allowed only with -E or -P\n", progname); 1310*80ab886dSwesolows exit(2); 1311*80ab886dSwesolows } 1312*80ab886dSwesolows if (op == CW_O_LINK && (ctx->i_flags & CW_F_SHADOW)) 1313*80ab886dSwesolows exit(0); 1314*80ab886dSwesolows 13157c478bd9Sstevel@tonic-gate if (model && !pic) 1316*80ab886dSwesolows newae(ctx->i_ae, model); 13177c478bd9Sstevel@tonic-gate if (!nolibc) 1318*80ab886dSwesolows newae(ctx->i_ae, "-lc"); 1319*80ab886dSwesolows if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) { 1320*80ab886dSwesolows newae(ctx->i_ae, "-o"); 1321*80ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 1322*80ab886dSwesolows } 1323*80ab886dSwesolows } 1324*80ab886dSwesolows 1325*80ab886dSwesolows static void 1326*80ab886dSwesolows do_cc(cw_ictx_t *ctx) 1327*80ab886dSwesolows { 1328*80ab886dSwesolows int in_output = 0, seen_o = 0; 1329*80ab886dSwesolows cw_op_t op = CW_O_LINK; 1330*80ab886dSwesolows 1331*80ab886dSwesolows while (--ctx->i_oldargc > 0) { 1332*80ab886dSwesolows char *arg = *++ctx->i_oldargv; 1333*80ab886dSwesolows 1334*80ab886dSwesolows if (*arg != '-') { 1335*80ab886dSwesolows if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) { 1336*80ab886dSwesolows newae(ctx->i_ae, arg); 1337*80ab886dSwesolows } else { 1338*80ab886dSwesolows in_output = 0; 1339*80ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 1340*80ab886dSwesolows } 1341*80ab886dSwesolows continue; 1342*80ab886dSwesolows } 1343*80ab886dSwesolows switch (*(arg + 1)) { 1344*80ab886dSwesolows case '_': 1345*80ab886dSwesolows if (strcmp(arg, "-_noecho") == 0) { 1346*80ab886dSwesolows ctx->i_flags &= ~CW_F_ECHO; 1347*80ab886dSwesolows } else if (strncmp(arg, "-_cc=", 5) == 0 || 1348*80ab886dSwesolows strncmp(arg, "-_CC=", 5) == 0) { 1349*80ab886dSwesolows newae(ctx->i_ae, arg + 5); 1350*80ab886dSwesolows } else if (strncmp(arg, "-_gcc=", 6) != 0 && 1351*80ab886dSwesolows strncmp(arg, "-_g++=", 6) != 0) { 1352*80ab886dSwesolows (void) fprintf(stderr, 1353*80ab886dSwesolows "%s: invalid argument '%s'\n", progname, 1354*80ab886dSwesolows arg); 1355*80ab886dSwesolows exit(2); 1356*80ab886dSwesolows } 1357*80ab886dSwesolows break; 1358*80ab886dSwesolows case 'V': 1359*80ab886dSwesolows ctx->i_flags &= ~CW_F_ECHO; 1360*80ab886dSwesolows newae(ctx->i_ae, arg); 1361*80ab886dSwesolows break; 1362*80ab886dSwesolows case 'o': 1363*80ab886dSwesolows seen_o = 1; 1364*80ab886dSwesolows if (strlen(arg) == 2) { 1365*80ab886dSwesolows in_output = 1; 1366*80ab886dSwesolows newae(ctx->i_ae, arg); 1367*80ab886dSwesolows } else if (ctx->i_flags & CW_F_SHADOW) { 1368*80ab886dSwesolows newae(ctx->i_ae, "-o"); 1369*80ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 1370*80ab886dSwesolows } else { 1371*80ab886dSwesolows newae(ctx->i_ae, arg); 1372*80ab886dSwesolows } 1373*80ab886dSwesolows break; 1374*80ab886dSwesolows case 'c': 1375*80ab886dSwesolows case 'S': 1376*80ab886dSwesolows op = CW_O_COMPILE; 1377*80ab886dSwesolows newae(ctx->i_ae, arg); 1378*80ab886dSwesolows break; 1379*80ab886dSwesolows case 'E': 1380*80ab886dSwesolows case 'P': 1381*80ab886dSwesolows op = CW_O_PREPROCESS; 1382*80ab886dSwesolows /*FALLTHROUGH*/ 1383*80ab886dSwesolows default: 1384*80ab886dSwesolows newae(ctx->i_ae, arg); 1385*80ab886dSwesolows } 1386*80ab886dSwesolows } 1387*80ab886dSwesolows 1388*80ab886dSwesolows if ((op == CW_O_LINK || op == CW_O_PREPROCESS) && 1389*80ab886dSwesolows (ctx->i_flags & CW_F_SHADOW)) 1390*80ab886dSwesolows exit(0); 1391*80ab886dSwesolows 1392*80ab886dSwesolows if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) { 1393*80ab886dSwesolows newae(ctx->i_ae, "-o"); 1394*80ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 1395*80ab886dSwesolows } 13967c478bd9Sstevel@tonic-gate } 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate static void 1399*80ab886dSwesolows prepctx(cw_ictx_t *ctx) 14007c478bd9Sstevel@tonic-gate { 1401*80ab886dSwesolows const char *dir, *cmd; 14027c478bd9Sstevel@tonic-gate char *program; 1403*80ab886dSwesolows size_t len; 14047c478bd9Sstevel@tonic-gate 1405*80ab886dSwesolows dir = dirs[CIDX(CC(ctx), ctx->i_flags)]; 1406*80ab886dSwesolows cmd = cmds[CIDX(CC(ctx), ctx->i_flags)]; 1407*80ab886dSwesolows len = strlen(dir) + strlen(cmd) + 2; 1408*80ab886dSwesolows if ((program = malloc(len)) == NULL) 1409*80ab886dSwesolows nomem(); 14107c478bd9Sstevel@tonic-gate (void) snprintf(program, len, "%s/%s", dir, cmd); 14117c478bd9Sstevel@tonic-gate 1412*80ab886dSwesolows newae(ctx->i_ae, program); 1413*80ab886dSwesolows 1414*80ab886dSwesolows if (!(ctx->i_flags & CW_F_XLATE)) 1415*80ab886dSwesolows return; 1416*80ab886dSwesolows 1417*80ab886dSwesolows switch (CC(ctx)) { 1418*80ab886dSwesolows case CW_C_CC: 1419*80ab886dSwesolows do_cc(ctx); 1420*80ab886dSwesolows break; 1421*80ab886dSwesolows case CW_C_GCC: 1422*80ab886dSwesolows do_gcc(ctx); 1423*80ab886dSwesolows break; 1424*80ab886dSwesolows } 1425*80ab886dSwesolows } 1426*80ab886dSwesolows 1427*80ab886dSwesolows static int 1428*80ab886dSwesolows invoke(cw_ictx_t *ctx) 1429*80ab886dSwesolows { 1430*80ab886dSwesolows char **newargv; 1431*80ab886dSwesolows int ac; 1432*80ab886dSwesolows struct ae *a; 1433*80ab886dSwesolows 1434*80ab886dSwesolows if ((newargv = calloc(sizeof (*newargv), ctx->i_ae->ael_argc + 1)) == 1435*80ab886dSwesolows NULL) 1436*80ab886dSwesolows nomem(); 1437*80ab886dSwesolows 1438*80ab886dSwesolows if (ctx->i_flags & CW_F_ECHO) 1439*80ab886dSwesolows (void) fprintf(stderr, "+ "); 1440*80ab886dSwesolows 1441*80ab886dSwesolows for (ac = 0, a = ctx->i_ae->ael_head; a; a = a->ae_next, ac++) { 1442*80ab886dSwesolows newargv[ac] = a->ae_arg; 1443*80ab886dSwesolows if (ctx->i_flags & CW_F_ECHO) 1444*80ab886dSwesolows (void) fprintf(stderr, "%s ", a->ae_arg); 1445*80ab886dSwesolows if (a == ctx->i_ae->ael_tail) 1446*80ab886dSwesolows break; 1447*80ab886dSwesolows } 1448*80ab886dSwesolows 1449*80ab886dSwesolows if (ctx->i_flags & CW_F_ECHO) { 1450*80ab886dSwesolows (void) fprintf(stderr, "\n"); 1451*80ab886dSwesolows (void) fflush(stderr); 1452*80ab886dSwesolows } 1453*80ab886dSwesolows 1454*80ab886dSwesolows if (!(ctx->i_flags & CW_F_EXEC)) 1455*80ab886dSwesolows return (0); 1456*80ab886dSwesolows 14577c478bd9Sstevel@tonic-gate /* 1458*80ab886dSwesolows * We must fix up the environment here so that the 1459*80ab886dSwesolows * dependency files are not trampled by the shadow compiler. 14607c478bd9Sstevel@tonic-gate */ 1461*80ab886dSwesolows if ((ctx->i_flags & CW_F_SHADOW) && 1462*80ab886dSwesolows (unsetenv("SUNPRO_DEPENDENCIES") != 0 || 1463*80ab886dSwesolows unsetenv("DEPENDENCIES_OUTPUT") != 0)) { 1464*80ab886dSwesolows (void) fprintf(stderr, "error: environment setup failed: %s\n", 1465*80ab886dSwesolows strerror(errno)); 1466*80ab886dSwesolows return (-1); 1467*80ab886dSwesolows } 14687c478bd9Sstevel@tonic-gate 1469*80ab886dSwesolows (void) execv(newargv[0], newargv); 1470*80ab886dSwesolows cw_perror("couldn't run %s", newargv[0]); 14717c478bd9Sstevel@tonic-gate 1472*80ab886dSwesolows return (-1); 1473*80ab886dSwesolows } 1474*80ab886dSwesolows 1475*80ab886dSwesolows static int 1476*80ab886dSwesolows reap(cw_ictx_t *ctx) 1477*80ab886dSwesolows { 1478*80ab886dSwesolows int stat, ret = 0; 1479*80ab886dSwesolows char buf[1024]; 1480*80ab886dSwesolows struct stat s; 1481*80ab886dSwesolows 1482*80ab886dSwesolows do { 1483*80ab886dSwesolows (void) waitpid(ctx->i_pid, &stat, 0); 1484*80ab886dSwesolows if (stat != 0) { 1485*80ab886dSwesolows if (WIFSIGNALED(stat)) { 1486*80ab886dSwesolows ret = -WTERMSIG(stat); 1487*80ab886dSwesolows break; 1488*80ab886dSwesolows } else if (WIFEXITED(stat)) { 1489*80ab886dSwesolows ret = WEXITSTATUS(stat); 1490*80ab886dSwesolows break; 1491*80ab886dSwesolows } 14927c478bd9Sstevel@tonic-gate } 1493*80ab886dSwesolows } while (!WIFEXITED(stat) && !WIFSIGNALED(stat)); 1494*80ab886dSwesolows 1495*80ab886dSwesolows (void) unlink(ctx->i_discard); 1496*80ab886dSwesolows 1497*80ab886dSwesolows if (fstat(ctx->i_fd[0], &s) < 0) { 1498*80ab886dSwesolows cw_perror("stat failed on child cleanup"); 1499*80ab886dSwesolows return (-1); 15007c478bd9Sstevel@tonic-gate } 1501*80ab886dSwesolows if (s.st_size != 0) { 1502*80ab886dSwesolows FILE *f = fdopen(ctx->i_fd[0], "r"); 1503*80ab886dSwesolows 1504*80ab886dSwesolows while (fgets(buf, sizeof (buf), f)) 1505*80ab886dSwesolows (void) fprintf(stderr, "%s", buf); 1506*80ab886dSwesolows (void) fflush(stderr); 1507*80ab886dSwesolows (void) fclose(f); 1508*80ab886dSwesolows } 1509*80ab886dSwesolows (void) close(ctx->i_fd[0]); 1510*80ab886dSwesolows 1511*80ab886dSwesolows return (ret); 1512*80ab886dSwesolows } 1513*80ab886dSwesolows 1514*80ab886dSwesolows static int 1515*80ab886dSwesolows exec_ctx(cw_ictx_t *ctx, int block) 1516*80ab886dSwesolows { 1517*80ab886dSwesolows char *file; 1518*80ab886dSwesolows 1519*80ab886dSwesolows /* 1520*80ab886dSwesolows * To avoid offending cc's sensibilities, the name of its output 1521*80ab886dSwesolows * file must end in '.o'. 1522*80ab886dSwesolows */ 1523*80ab886dSwesolows if ((file = tempnam(NULL, ".cw")) == NULL) { 1524*80ab886dSwesolows nomem(); 1525*80ab886dSwesolows return (-1); 1526*80ab886dSwesolows } 1527*80ab886dSwesolows (void) strlcpy(ctx->i_discard, file, MAXPATHLEN); 1528*80ab886dSwesolows (void) strlcat(ctx->i_discard, ".o", MAXPATHLEN); 1529*80ab886dSwesolows free(file); 1530*80ab886dSwesolows 1531*80ab886dSwesolows if (pipe(ctx->i_fd) < 0) { 1532*80ab886dSwesolows cw_perror("pipe creation failed"); 1533*80ab886dSwesolows return (-1); 1534*80ab886dSwesolows } 1535*80ab886dSwesolows 1536*80ab886dSwesolows if ((ctx->i_pid = fork()) == 0) { 1537*80ab886dSwesolows (void) close(ctx->i_fd[0]); 1538*80ab886dSwesolows (void) fclose(stderr); 1539*80ab886dSwesolows if (dup2(ctx->i_fd[1], 2) < 0) { 1540*80ab886dSwesolows cw_perror("dup2 failed for standard error"); 1541*80ab886dSwesolows exit(1); 1542*80ab886dSwesolows } 1543*80ab886dSwesolows (void) close(ctx->i_fd[1]); 1544*80ab886dSwesolows if (freopen("/dev/fd/2", "w", stderr) == NULL) { 1545*80ab886dSwesolows cw_perror("freopen failed for /dev/fd/2"); 1546*80ab886dSwesolows exit(1); 1547*80ab886dSwesolows } 1548*80ab886dSwesolows prepctx(ctx); 1549*80ab886dSwesolows exit(invoke(ctx)); 1550*80ab886dSwesolows } 1551*80ab886dSwesolows 1552*80ab886dSwesolows if (ctx->i_pid < 0) { 1553*80ab886dSwesolows cw_perror("fork failed"); 1554*80ab886dSwesolows return (1); 1555*80ab886dSwesolows } 1556*80ab886dSwesolows (void) close(ctx->i_fd[1]); 1557*80ab886dSwesolows 1558*80ab886dSwesolows if (block) 1559*80ab886dSwesolows return (reap(ctx)); 1560*80ab886dSwesolows 1561*80ab886dSwesolows return (0); 15627c478bd9Sstevel@tonic-gate } 15637c478bd9Sstevel@tonic-gate 15647c478bd9Sstevel@tonic-gate int 15657c478bd9Sstevel@tonic-gate main(int argc, char **argv) 15667c478bd9Sstevel@tonic-gate { 1567*80ab886dSwesolows cw_ictx_t *ctx = newictx(); 1568*80ab886dSwesolows cw_ictx_t *ctx_shadow = newictx(); 15697c478bd9Sstevel@tonic-gate const char *dir; 15707c478bd9Sstevel@tonic-gate char cc_buf[MAXPATHLEN], gcc_buf[MAXPATHLEN]; 1571*80ab886dSwesolows int do_serial, do_shadow; 1572*80ab886dSwesolows int ret = 0; 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate if ((progname = strrchr(argv[0], '/')) == NULL) 15757c478bd9Sstevel@tonic-gate progname = argv[0]; 15767c478bd9Sstevel@tonic-gate else 15777c478bd9Sstevel@tonic-gate progname++; 15787c478bd9Sstevel@tonic-gate 1579*80ab886dSwesolows if (ctx == NULL || ctx_shadow == NULL) 1580*80ab886dSwesolows nomem(); 1581*80ab886dSwesolows 1582*80ab886dSwesolows ctx->i_flags = CW_F_ECHO|CW_F_XLATE; 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * Figure out where to get our tools from. This depends on 15867c478bd9Sstevel@tonic-gate * the environment variables set at run time. 15877c478bd9Sstevel@tonic-gate */ 15887c478bd9Sstevel@tonic-gate if ((dir = getenv("SPRO_VROOT")) != NULL) { 15897c478bd9Sstevel@tonic-gate (void) snprintf(cc_buf, MAXPATHLEN, "%s/bin", dir); 15907c478bd9Sstevel@tonic-gate } else if ((dir = getenv("SPRO_ROOT")) != NULL) { 159135a86aa1Spetede (void) snprintf(cc_buf, MAXPATHLEN, "%s/SOS10/bin", dir); 15927c478bd9Sstevel@tonic-gate } else if ((dir = getenv("BUILD_TOOLS")) != NULL) { 15937c478bd9Sstevel@tonic-gate (void) snprintf(cc_buf, MAXPATHLEN, 159435a86aa1Spetede "%s/SUNWspro/SOS10/bin", dir); 15957c478bd9Sstevel@tonic-gate } 1596*80ab886dSwesolows if (dir != NULL) { 1597*80ab886dSwesolows dirs[CIDX(CW_C_CC, 0)] = (const char *)cc_buf; 1598*80ab886dSwesolows dirs[CIDX(CW_C_CC, CW_F_CXX)] = (const char *)cc_buf; 1599*80ab886dSwesolows } 16007c478bd9Sstevel@tonic-gate 16017c478bd9Sstevel@tonic-gate if ((dir = getenv("GNU_ROOT")) != NULL) { 16027c478bd9Sstevel@tonic-gate (void) snprintf(gcc_buf, MAXPATHLEN, "%s/bin", dir); 1603*80ab886dSwesolows dirs[CIDX(CW_C_GCC, 0)] = (const char *)gcc_buf; 1604*80ab886dSwesolows dirs[CIDX(CW_C_GCC, CW_F_CXX)] = (const char *)gcc_buf; 16057c478bd9Sstevel@tonic-gate } 16067c478bd9Sstevel@tonic-gate 1607*80ab886dSwesolows if ((dir = getenv("CW_CC_DIR")) != NULL) 1608*80ab886dSwesolows dirs[CIDX(CW_C_CC, 0)] = dir; 1609*80ab886dSwesolows if ((dir = getenv("CW_CPLUSPLUS_DIR")) != NULL) 1610*80ab886dSwesolows dirs[CIDX(CW_C_CC, CW_F_CXX)] = dir; 1611*80ab886dSwesolows if ((dir = getenv("CW_GCC_DIR")) != NULL) 1612*80ab886dSwesolows dirs[CIDX(CW_C_GCC, 0)] = dir; 1613*80ab886dSwesolows if ((dir = getenv("CW_GPLUSPLUS_DIR")) != NULL) 1614*80ab886dSwesolows dirs[CIDX(CW_C_GCC, CW_F_CXX)] = dir; 1615*80ab886dSwesolows 1616*80ab886dSwesolows do_shadow = (getenv("CW_NO_SHADOW") ? 0 : 1); 1617*80ab886dSwesolows do_serial = (getenv("CW_SHADOW_SERIAL") ? 1 : 0); 1618*80ab886dSwesolows 1619*80ab886dSwesolows if (getenv("CW_NO_EXEC") == NULL) 1620*80ab886dSwesolows ctx->i_flags |= CW_F_EXEC; 16217c478bd9Sstevel@tonic-gate 16227c478bd9Sstevel@tonic-gate /* 16237c478bd9Sstevel@tonic-gate * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++" 16247c478bd9Sstevel@tonic-gate */ 16257c478bd9Sstevel@tonic-gate if (argc == 1) 16267c478bd9Sstevel@tonic-gate usage(); 16277c478bd9Sstevel@tonic-gate argc--; 16287c478bd9Sstevel@tonic-gate argv++; 16297c478bd9Sstevel@tonic-gate if (strcmp(argv[0], "-_cc") == 0) { 1630*80ab886dSwesolows ctx->i_compiler = CW_C_CC; 16317c478bd9Sstevel@tonic-gate } else if (strcmp(argv[0], "-_gcc") == 0) { 1632*80ab886dSwesolows ctx->i_compiler = CW_C_GCC; 16337c478bd9Sstevel@tonic-gate } else if (strcmp(argv[0], "-_CC") == 0) { 1634*80ab886dSwesolows ctx->i_compiler = CW_C_CC; 1635*80ab886dSwesolows ctx->i_flags |= CW_F_CXX; 16367c478bd9Sstevel@tonic-gate } else if (strcmp(argv[0], "-_g++") == 0) { 1637*80ab886dSwesolows ctx->i_compiler = CW_C_GCC; 1638*80ab886dSwesolows ctx->i_flags |= CW_F_CXX; 16397c478bd9Sstevel@tonic-gate } else { 16407c478bd9Sstevel@tonic-gate /* assume "-_gcc" by default */ 16417c478bd9Sstevel@tonic-gate argc++; 16427c478bd9Sstevel@tonic-gate argv--; 1643*80ab886dSwesolows ctx->i_compiler = CW_C_GCC; 16447c478bd9Sstevel@tonic-gate } 16457c478bd9Sstevel@tonic-gate 1646*80ab886dSwesolows ctx->i_oldargc = argc; 1647*80ab886dSwesolows ctx->i_oldargv = argv; 16487c478bd9Sstevel@tonic-gate 1649*80ab886dSwesolows if (argc > 1 && strcmp(argv[1], "-_compiler") == 0) { 1650*80ab886dSwesolows ctx->i_flags &= ~CW_F_XLATE; 1651*80ab886dSwesolows prepctx(ctx); 1652*80ab886dSwesolows (void) printf("%s\n", ctx->i_ae->ael_head->ae_arg); 1653*80ab886dSwesolows return (0); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate 1656*80ab886dSwesolows ret |= exec_ctx(ctx, do_serial); 1657*80ab886dSwesolows 1658*80ab886dSwesolows if (do_shadow) { 1659*80ab886dSwesolows (void) memcpy(ctx_shadow, ctx, sizeof (cw_ictx_t)); 1660*80ab886dSwesolows ctx_shadow->i_flags |= CW_F_SHADOW; 1661*80ab886dSwesolows ret |= exec_ctx(ctx_shadow, 1); 16627c478bd9Sstevel@tonic-gate } 16637c478bd9Sstevel@tonic-gate 1664*80ab886dSwesolows if (!do_serial) 1665*80ab886dSwesolows ret |= reap(ctx); 16667c478bd9Sstevel@tonic-gate 1667*80ab886dSwesolows return (ret); 16687c478bd9Sstevel@tonic-gate } 1669