20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2018, Richard Lowe.
25 */
26 /*
27 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 /*
32 * Wrapper for the GNU C compiler to make it accept the Sun C compiler
33 * arguments where possible.
34 *
35 * Since the translation is inexact, this is something of a work-in-progress.
36 *
37 */
38
39 /* If you modify this file, you must increment CW_VERSION */
40 #define CW_VERSION "2.0"
41
42 /*
43 * -# Verbose mode
44 * -### Show compiler commands built by driver, no compilation
45 * -A<name[(tokens)]> Preprocessor predicate assertion
46 * -B<[static|dynamic]> Specify dynamic or static binding
47 * -C Prevent preprocessor from removing comments
48 * -c Compile only - produce .o files, suppress linking
49 * -cg92 Alias for -xtarget=ss1000
50 * -D<name[=token]> Associate name with token as if by #define
51 * -d[y|n] dynamic [-dy] or static [-dn] option to linker
52 * -E Compile source through preprocessor only, output to stdout
53 * -erroff=<t> Suppress warnings specified by tags t(%none, %all, <tag list>)
54 * -errtags=<a> Display messages with tags a(no, yes)
55 * -errwarn=<t> Treats warnings specified by tags t(%none, %all, <tag list>)
56 * as errors
57 * -fast Optimize using a selection of options
58 * -fd Report old-style function definitions and declarations
59 * -features=zla Allow zero-length arrays
60 * -flags Show this summary of compiler options
61 * -fnonstd Initialize floating-point hardware to non-standard preferences
62 * -fns[=<yes|no>] Select non-standard floating point mode
63 * -fprecision=<p> Set FP rounding precision mode p(single, double, extended)
64 * -fround=<r> Select the IEEE rounding mode in effect at startup
65 * -fsimple[=<n>] Select floating-point optimization preferences <n>
66 * -fsingle Use single-precision arithmetic (-Xt and -Xs modes only)
67 * -ftrap=<t> Select floating-point trapping mode in effect at startup
68 * -fstore force floating pt. values to target precision on assignment
69 * -G Build a dynamic shared library
70 * -g Compile for debugging
71 * -H Print path name of each file included during compilation
72 * -h <name> Assign <name> to generated dynamic shared library
73 * -I<dir> Add <dir> to preprocessor #include file search path
74 * -i Passed to linker to ignore any LD_LIBRARY_PATH setting
75 * -keeptmp Keep temporary files created during compilation
76 * -KPIC Compile position independent code with 32-bit addresses
77 * -Kpic Compile position independent code
78 * -L<dir> Pass to linker to add <dir> to the library search path
79 * -l<name> Link with library lib<name>.a or lib<name>.so
80 * -mc Remove duplicate strings from .comment section of output files
81 * -mr Remove all strings from .comment section of output files
82 * -mr,"string" Remove all strings and append "string" to .comment section
83 * -mt Specify options needed when compiling multi-threaded code
84 * -native Find available processor, generate code accordingly
85 * -nofstore Do not force floating pt. values to target precision
86 * on assignment
87 * -nolib Same as -xnolib
88 * -noqueue Disable queuing of compiler license requests
89 * -norunpath Do not build in a runtime path for shared libraries
90 * -O Use default optimization level (-xO2 or -xO3. Check man page.)
91 * -o <outputfile> Set name of output file to <outputfile>
92 * -P Compile source through preprocessor only, output to .i file
93 * -PIC Alias for -KPIC or -xcode=pic32
94 * -p Compile for profiling with prof
95 * -pic Alias for -Kpic or -xcode=pic13
96 * -Q[y|n] Emit/don't emit identification info to output file
97 * -qp Compile for profiling with prof
98 * -R<dir[:dir]> Build runtime search path list into executable
99 * -S Compile and only generate assembly code (.s)
100 * -s Strip symbol table from the executable file
101 * -t Turn off duplicate symbol warnings when linking
102 * -U<name> Delete initial definition of preprocessor symbol <name>
103 * -V Report version number of each compilation phase
104 * -v Do stricter semantic checking
105 * -W<c>,<arg> Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
106 * -w Suppress compiler warning messages
107 * -Xa Compile assuming ANSI C conformance, allow K & R extensions
108 * (default mode)
109 * -Xc Compile assuming strict ANSI C conformance
110 * -Xs Compile assuming (pre-ANSI) K & R C style code
111 * -Xt Compile assuming K & R conformance, allow ANSI C
112 * -x386 Generate code for the 80386 processor
113 * -x486 Generate code for the 80486 processor
114 * -xarch=<a> Specify target architecture instruction set
115 * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
116 * for system functions, b={%all,%none}
117 * -xCC Accept C++ style comments
118 * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low)
119 * -xchip=<c> Specify the target processor for use by the optimizer
120 * -xcode=<c> Generate different code for forming addresses
121 * -xcrossfile[=<n>] Enable optimization and inlining across source files,
122 * n={0|1}
123 * -xe Perform only syntax/semantic checking, no code generation
124 * -xF Compile for later mapfile reordering or unused section
125 * elimination
126 * -xhelp=<f> Display on-line help information f(flags, readme, errors)
127 * -xildoff Cancel -xildon
128 * -xildon Enable use of the incremental linker, ild
129 * -xinline=[<a>,...,<a>] Attempt inlining of specified user routines,
130 * <a>={%auto,func,no%func}
131 * -xlibmieee Force IEEE 754 return values for math routines in
132 * exceptional cases
133 * -xlibmil Inline selected libm math routines for optimization
134 * -xlic_lib=sunperf Link in the Sun supplied performance libraries
135 * -xlicinfo Show license server information
136 * -xM Generate makefile dependencies
137 * -xM1 Generate makefile dependencies, but exclude /usr/include
138 * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
139 * -xnolib Do not link with default system libraries
140 * -xnolibmil Cancel -xlibmil on command line
141 * -xO<n> Generate optimized code (n={1|2|3|4|5})
142 * -xP Print prototypes for function definitions
143 * -xpentium Generate code for the pentium processor
144 * -xpg Compile for profiling with gprof
145 * -xprofile=<p> Collect data for a profile or use a profile to optimize
146 * <p>={{collect,use}[:<path>],tcov}
147 * -xregs=<r> Control register allocation
148 * -xs Allow debugging without object (.o) files
149 * -xsb Compile for use with the WorkShop source browser
150 * -xsbfast Generate only WorkShop source browser info, no compilation
151 * -xsfpconst Represent unsuffixed floating point constants as single
152 * precision
153 * -xspace Do not do optimizations that increase code size
154 * -xstrconst Place string literals into read-only data segment
155 * -xtarget=<t> Specify target system for optimization
156 * -xtemp=<dir> Set directory for temporary files to <dir>
157 * -xtime Report the execution time for each compilation phase
158 * -xtransition Emit warnings for differences between K&R C and ANSI C
159 * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation
160 * -xunroll=n Enable unrolling loops n times where possible
161 * -Y<c>,<dir> Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
162 * -YA,<dir> Change default directory searched for components
163 * -YI,<dir> Change default directory searched for include files
164 * -YP,<dir> Change default directory for finding libraries files
165 * -YS,<dir> Change default directory for startup object files
166 */
167
168 /*
169 * Translation table:
170 */
171 /*
172 * -# -v
173 * -### error
174 * -A<name[(tokens)]> pass-thru
175 * -B<[static|dynamic]> pass-thru (syntax error for anything else)
176 * -C pass-thru
177 * -c pass-thru
178 * -cg92 -m32 -mcpu=v8 -mtune=supersparc (SPARC only)
179 * -D<name[=token]> pass-thru
180 * -dy or -dn -Wl,-dy or -Wl,-dn
181 * -E pass-thru
182 * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
183 * -errtags=%all -Wall
184 * -errwarn=%all -Werror else -Wno-error
185 * -fast error
186 * -fd error
187 * -features=zla ignore
188 * -flags --help
189 * -fnonstd error
190 * -fns[=<yes|no>] error
191 * -fprecision=<p> error
192 * -fround=<r> error
193 * -fsimple[=<n>] error
194 * -fsingle[=<n>] error
195 * -ftrap=<t> error
196 * -fstore error
197 * -G pass-thru
198 * -g pass-thru
199 * -H pass-thru
200 * -h <name> pass-thru
201 * -I<dir> pass-thru
202 * -i pass-thru
203 * -keeptmp -save-temps
204 * -KPIC -fPIC
205 * -Kpic -fpic
206 * -L<dir> pass-thru
207 * -l<name> pass-thru
208 * -mc error
209 * -mr error
210 * -mr,"string" error
211 * -mt -D_REENTRANT
212 * -native error
213 * -nofstore error
214 * -nolib -nodefaultlibs
215 * -noqueue ignore
216 * -norunpath ignore
217 * -O -O1 (Check the man page to be certain)
218 * -o <outputfile> pass-thru
219 * -P -E -o filename.i (or error)
220 * -PIC -fPIC (C++ only)
221 * -p pass-thru
222 * -pic -fpic (C++ only)
223 * -Q[y|n] error
224 * -qp -p
225 * -R<dir[:dir]> pass-thru
226 * -S pass-thru
227 * -s -Wl,-s
228 * -t -Wl,-t
229 * -U<name> pass-thru
230 * -V --version
231 * -v -Wall
232 * -Wa,<arg> pass-thru
233 * -Wp,<arg> pass-thru except -xc99=<a>
234 * -Wl,<arg> pass-thru
235 * -W{m,0,2,h,i,u> error/ignore
236 * -Wu,-xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone
237 * -xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone
238 * -Wu,-save_args -msave-args
239 * -w pass-thru
240 * -Xa -std=iso9899:199409 or -ansi
241 * -Xc -ansi -pedantic
242 * -Xt error
243 * -Xs -traditional -std=c89
244 * -x386 -march=i386 (x86 only)
245 * -x486 -march=i486 (x86 only)
246 * -xarch=<a> table
247 * -xbuiltin[=<b>] -fbuiltin (-fno-builtin otherwise)
248 * -xCC ignore
249 * -xchar_byte_order=<o> error
250 * -xchip=<c> table
251 * -xcode=<c> table
252 * -xdebugformat=<format> ignore (always use dwarf-2 for gcc)
253 * -xcrossfile[=<n>] ignore
254 * -xe error
255 * -xF error
256 * -xhelp=<f> error
257 * -xildoff ignore
258 * -xildon ignore
259 * -xinline ignore
260 * -xlibmieee error
261 * -xlibmil error
262 * -xlic_lib=sunperf error
263 * -xM -M
264 * -xM1 -MM
265 * -xmaxopt=[...] error
266 * -xnolib -nodefaultlibs
267 * -xnolibmil error
268 * -xO<n> -O<n>
269 * -xP error
270 * -xpentium -march=pentium (x86 only)
271 * -xpg error
272 * -xprofile=<p> error
273 * -xregs=<r> table
274 * -xs error
275 * -xsb error
276 * -xsbfast error
277 * -xsfpconst error
278 * -xspace ignore (-not -Os)
279 * -xstrconst ignore
280 * -xtarget=<t> table
281 * -xtemp=<dir> error
282 * -xtime error
283 * -xtransition -Wtransition
284 * -xtrigraphs=<yes|no> -trigraphs -notrigraphs
285 * -xunroll=n error
286 * -W0,-xdbggen=no%usedonly -fno-eliminate-unused-debug-symbols
287 * -fno-eliminate-unused-debug-types
288 * -Y<c>,<dir> error
289 * -YA,<dir> error
290 * -YI,<dir> -nostdinc -I<dir>
291 * -YP,<dir> error
292 * -YS,<dir> error
293 */
294
295 #include <ctype.h>
296 #include <err.h>
297 #include <errno.h>
298 #include <fcntl.h>
299 #include <getopt.h>
300 #include <stdio.h>
301 #include <stdlib.h>
302 #include <string.h>
303 #include <unistd.h>
304
510 newae(h, "-Wextra");
511 }
512
513 static void
514 optim_disable(struct aelist *h, int level)
515 {
516 if (level >= 2) {
517 newae(h, "-fno-strict-aliasing");
518 newae(h, "-fno-unit-at-a-time");
519 newae(h, "-fno-optimize-sibling-calls");
520 }
521 }
522
523 /* ARGSUSED */
524 static void
525 Xamode(struct aelist __unused *h)
526 {
527 }
528
529 static void
530 Xcmode(struct aelist *h)
531 {
532 static int xconce;
533
534 if (xconce++)
535 return;
536
537 newae(h, "-ansi");
538 newae(h, "-pedantic-errors");
539 }
540
541 static void
542 Xsmode(struct aelist *h)
543 {
544 static int xsonce;
545
546 if (xsonce++)
547 return;
548
549 newae(h, "-traditional");
550 newae(h, "-traditional-cpp");
551 }
552
553 static void
554 usage()
555 {
556 extern char *__progname;
557 (void) fprintf(stderr,
558 "usage: %s [-C] [--versions] --primary <compiler> "
559 "[--shadow <compiler>]... -- cflags...\n",
560 __progname);
561 (void) fprintf(stderr, "compilers take the form: name,path,style\n"
702 newae(ctx->i_ae, strchr(arg, '=') + 1);
703 continue;
704 }
705 if (strncmp(arg, "-compat=", 8) == 0) {
706 /* discard -compat=4 and -compat=5 */
707 continue;
708 }
709 if (strcmp(arg, "-Qoption") == 0) {
710 /* discard -Qoption and its two arguments */
711 if (ctx->i_oldargc < 3)
712 error(arg);
713 ctx->i_oldargc -= 2;
714 ctx->i_oldargv += 2;
715 continue;
716 }
717 if (strcmp(arg, "-xwe") == 0) {
718 /* turn warnings into errors */
719 newae(ctx->i_ae, "-Werror");
720 continue;
721 }
722 if (strcmp(arg, "-noex") == 0) {
723 /* no exceptions */
724 newae(ctx->i_ae, "-fno-exceptions");
725 /* no run time type descriptor information */
726 newae(ctx->i_ae, "-fno-rtti");
727 continue;
728 }
729 if (strcmp(arg, "-pic") == 0) {
730 newae(ctx->i_ae, "-fpic");
731 pic = 1;
732 continue;
733 }
734 if (strcmp(arg, "-PIC") == 0) {
735 newae(ctx->i_ae, "-fPIC");
736 pic = 1;
737 continue;
738 }
739 if (strcmp(arg, "-norunpath") == 0) {
740 /* gcc has no corresponding option */
741 continue;
742 }
743 if (strcmp(arg, "-nolib") == 0) {
744 /* -nodefaultlibs is on by default */
745 nolibc = 1;
746 continue;
747 }
748 #if defined(__sparc)
749 if (strcmp(arg, "-cg92") == 0) {
750 mflag |= xlate_xtb(ctx->i_ae, "v8");
751 xlate(ctx->i_ae, "super", xchip_tbl);
752 continue;
753 }
754 #endif /* __sparc */
755 }
756
757 switch ((c = arg[1])) {
758 case '_':
857 /*
858 * Accept but ignore this -- gcc doesn't
859 * seem to complain about empty translation
860 * units
861 */
862 break;
863 }
864 /* XX64 -- ignore all -erroff= options, for now */
865 if (strncmp(arg, "-erroff=", 8) == 0)
866 break;
867 if (strcmp(arg, "-errtags=yes") == 0) {
868 warnings(ctx->i_ae);
869 break;
870 }
871 if (strcmp(arg, "-errwarn=%all") == 0) {
872 newae(ctx->i_ae, "-Werror");
873 break;
874 }
875 error(arg);
876 break;
877 case 'f':
878 if (strcmp(arg, "-flags") == 0) {
879 newae(ctx->i_ae, "--help");
880 break;
881 }
882 if (strncmp(arg, "-features=zla", 13) == 0) {
883 /*
884 * Accept but ignore this -- gcc allows
885 * zero length arrays.
886 */
887 break;
888 }
889 error(arg);
890 break;
891 case 'G':
892 newae(ctx->i_ae, "-shared");
893 nolibc = 1;
894 break;
895 case 'k':
896 if (strcmp(arg, "-keeptmp") == 0) {
897 newae(ctx->i_ae, "-save-temps");
898 break;
899 }
900 error(arg);
901 break;
902 case 'K':
903 if (arglen == 1) {
904 if ((arg = *++ctx->i_oldargv) == NULL ||
905 *arg == '\0')
906 error("-K");
907 ctx->i_oldargc--;
908 } else {
909 arg += 2;
910 }
947 char *opt;
948 size_t len;
949 char *s;
950
951 if (arglen == 1) {
952 opt = *++ctx->i_oldargv;
953 if (opt == NULL || *opt == '\0')
954 error(arg);
955 ctx->i_oldargc--;
956 } else {
957 opt = arg + 2;
958 }
959 len = strlen(opt) + 7;
960 if ((s = malloc(len)) == NULL)
961 nomem();
962 (void) snprintf(s, len, "-Wl,-%c%s", c, opt);
963 newae(ctx->i_ae, s);
964 free(s);
965 }
966 break;
967 case 'n':
968 if (strcmp(arg, "-noqueue") == 0) {
969 /*
970 * Horrid license server stuff - n/a
971 */
972 break;
973 }
974 error(arg);
975 break;
976 case 'O':
977 if (arglen == 1) {
978 newae(ctx->i_ae, "-O");
979 break;
980 }
981 error(arg);
982 break;
983 case 'P':
984 /*
985 * We could do '-E -o filename.i', but that's hard,
986 * and we don't need it for the case that's triggering
987 * this addition. We'll require the user to specify
988 * -o in the Makefile. If they don't they'll find out
989 * in a hurry.
990 */
991 newae(ctx->i_ae, "-E");
992 op = CW_O_PREPROCESS;
993 nolibc = 1;
994 break;
995 case 'q':
996 if (strcmp(arg, "-qp") == 0) {
997 newae(ctx->i_ae, "-p");
998 break;
999 }
1000 error(arg);
1001 break;
1002 case 's':
1003 if (arglen == 1) {
1004 newae(ctx->i_ae, "-Wl,-s");
1005 break;
1006 }
1007 error(arg);
1008 break;
1009 case 't':
1010 if (arglen == 1) {
1011 newae(ctx->i_ae, "-Wl,-t");
1012 break;
1013 }
1014 error(arg);
1015 break;
1016 case 'V':
1017 if (arglen == 1) {
1018 ctx->i_flags &= ~CW_F_ECHO;
1019 newae(ctx->i_ae, "--version");
1020 break;
1021 }
1025 if (arglen == 1) {
1026 warnings(ctx->i_ae);
1027 break;
1028 }
1029 error(arg);
1030 break;
1031 case 'W':
1032 if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
1033 /*
1034 * gcc's preprocessor will accept c99
1035 * regardless, so accept and ignore.
1036 */
1037 break;
1038 }
1039 if (strncmp(arg, "-Wa,", 4) == 0 ||
1040 strncmp(arg, "-Wp,", 4) == 0 ||
1041 strncmp(arg, "-Wl,", 4) == 0) {
1042 newae(ctx->i_ae, arg);
1043 break;
1044 }
1045 if (strcmp(arg, "-W0,-xc99=pragma") == 0) {
1046 /* (undocumented) enables _Pragma */
1047 break;
1048 }
1049 if (strcmp(arg, "-W0,-xc99=%none") == 0) {
1050 /*
1051 * This is a polite way of saying
1052 * "no c99 constructs allowed!"
1053 * For now, just accept and ignore this.
1054 */
1055 break;
1056 }
1057 if (strcmp(arg, "-W0,-noglobal") == 0 ||
1058 strcmp(arg, "-W0,-xglobalstatic") == 0) {
1059 /*
1060 * gcc doesn't prefix local symbols
1061 * in debug mode, so this is not needed.
1062 */
1063 break;
1064 }
1065 if (strcmp(arg, "-W0,-Lt") == 0) {
1066 /*
1067 * Generate tests at the top of loops.
1068 * There is no direct gcc equivalent, ignore.
1069 */
1070 break;
1071 }
1072 if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) {
1073 newae(ctx->i_ae,
1074 "-fno-eliminate-unused-debug-symbols");
1075 newae(ctx->i_ae,
1076 "-fno-eliminate-unused-debug-types");
1077 break;
1078 }
1079 if (strcmp(arg, "-W2,-xwrap_int") == 0) {
1080 /*
1081 * Use the legacy behaviour (pre-SS11)
1082 * for integer wrapping.
1083 * gcc does not need this.
1084 */
1085 break;
1086 }
1087 if (strcmp(arg, "-W2,-Rcond_elim") == 0) {
1088 /*
1089 * Elimination and expansion of conditionals;
1090 * gcc has no direct equivalent.
1091 */
1092 break;
1093 }
1094 if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
1095 /*
1096 * Prevents optimizing away checks for
1097 * unbound weak symbol addresses. gcc does
1098 * not do this, so it's not needed.
1099 */
1100 break;
1101 }
1102 if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
1103 xlate(ctx->i_ae, arg + 11, xcode_tbl);
1104 if (strncmp(arg + 11, "pic", 3) == 0)
1105 pic = 1;
1106 break;
1107 }
1108 if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
1109 /*
1110 * Prevents insertion of register symbols.
1111 * gcc doesn't do this, so ignore it.
1112 */
1113 break;
1114 }
1115 if (strcmp(arg, "-Wc,-Qassembler-ounrefsym=0") == 0) {
1116 /*
1117 * Prevents optimizing away of static variables.
1118 * gcc does not do this, so it's not needed.
1119 */
1120 break;
1121 }
1122 #if defined(__x86)
1123 if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) {
1124 newae(ctx->i_ae, "-ffreestanding");
1125 newae(ctx->i_ae, "-mno-red-zone");
1126 model = "-mcmodel=kernel";
1127 nolibc = 1;
1128 break;
1129 }
1130 if (strcmp(arg, "-Wu,-save_args") == 0) {
1131 newae(ctx->i_ae, "-msave-args");
1132 break;
1133 }
1134 #endif /* __x86 */
1135 error(arg);
1136 break;
1137 case 'X':
1138 if (strcmp(arg, "-Xa") == 0 ||
1139 strcmp(arg, "-Xt") == 0) {
1140 Xamode(ctx->i_ae);
1141 break;
1142 }
1143 if (strcmp(arg, "-Xc") == 0) {
1144 Xcmode(ctx->i_ae);
1145 break;
1146 }
1147 if (strcmp(arg, "-Xs") == 0) {
1148 Xsmode(ctx->i_ae);
1149 break;
1150 }
1151 error(arg);
1152 break;
1153 case 'x':
1154 if (arglen == 1)
1155 error(arg);
1156 switch (arg[2]) {
1157 #if defined(__x86)
1158 case '3':
1159 if (strcmp(arg, "-x386") == 0) {
1160 newae(ctx->i_ae, "-march=i386");
1161 break;
1162 }
1163 error(arg);
1164 break;
1165 case '4':
1166 if (strcmp(arg, "-x486") == 0) {
1167 newae(ctx->i_ae, "-march=i486");
1168 break;
1169 }
1170 error(arg);
1171 break;
1172 #endif /* __x86 */
1173 case 'a':
1174 if (strncmp(arg, "-xarch=", 7) == 0) {
1175 mflag |= xlate_xtb(ctx->i_ae, arg + 7);
1176 break;
1177 }
1178 error(arg);
1179 break;
1180 case 'b':
1181 if (strncmp(arg, "-xbuiltin=", 10) == 0) {
1182 if (strcmp(arg + 10, "%all"))
1183 newae(ctx->i_ae, "-fbuiltin");
1184 break;
1185 }
1186 error(arg);
1187 break;
1188 case 'C':
1189 /* Accept C++ style comments -- ignore */
1190 if (strcmp(arg, "-xCC") == 0)
1191 break;
1192 error(arg);
1193 break;
1194 case 'c':
1195 if (strncmp(arg, "-xc99=%all", 10) == 0) {
1196 newae(ctx->i_ae, "-std=gnu99");
1197 break;
1198 }
1199 if (strncmp(arg, "-xc99=%none", 11) == 0) {
1200 newae(ctx->i_ae, "-std=gnu89");
1201 break;
1202 }
1203 if (strncmp(arg, "-xchip=", 7) == 0) {
1204 xlate(ctx->i_ae, arg + 7, xchip_tbl);
1205 break;
1206 }
1207 if (strncmp(arg, "-xcode=", 7) == 0) {
1208 xlate(ctx->i_ae, arg + 7, xcode_tbl);
1209 if (strncmp(arg + 7, "pic", 3) == 0)
1210 pic = 1;
1211 break;
1212 }
1213 if (strncmp(arg, "-xcache=", 8) == 0)
1214 break;
1215 if (strncmp(arg, "-xcrossfile", 11) == 0)
1216 break;
1217 error(arg);
1218 break;
1219 case 'd':
1220 if (strcmp(arg, "-xdepend") == 0)
1221 break;
1222 if (strncmp(arg, "-xdebugformat=", 14) == 0)
1223 break;
1224 error(arg);
1225 break;
1226 case 'F':
1227 /*
1228 * Compile for mapfile reordering, or unused
1229 * section elimination, syntax can be -xF or
1230 * more complex, like -xF=%all -- ignore.
1231 */
1232 if (strncmp(arg, "-xF", 3) == 0)
1233 break;
1234 error(arg);
1235 break;
1236 case 'i':
1237 if (strncmp(arg, "-xinline", 8) == 0)
1238 /* No inlining; ignore */
1239 break;
1240 if (strcmp(arg, "-xildon") == 0 ||
1241 strcmp(arg, "-xildoff") == 0)
1242 /* No incremental linking; ignore */
1243 break;
1244 error(arg);
1245 break;
1246 #if defined(__x86)
1247 case 'm':
1248 if (strcmp(arg, "-xmodel=kernel") == 0) {
1249 newae(ctx->i_ae, "-ffreestanding");
1250 newae(ctx->i_ae, "-mno-red-zone");
1251 model = "-mcmodel=kernel";
1252 nolibc = 1;
1253 break;
1254 }
1255 error(arg);
1256 break;
1257 #endif /* __x86 */
1258 case 'M':
1259 if (strcmp(arg, "-xM") == 0) {
1260 newae(ctx->i_ae, "-M");
1261 break;
1262 }
1263 if (strcmp(arg, "-xM1") == 0) {
1264 newae(ctx->i_ae, "-MM");
1265 break;
1266 }
1267 error(arg);
1268 break;
1269 case 'n':
1270 if (strcmp(arg, "-xnolib") == 0) {
1271 nolibc = 1;
1272 break;
1273 }
1274 error(arg);
1275 break;
1276 case 'O':
1277 if (strncmp(arg, "-xO", 3) == 0) {
1278 size_t len = strlen(arg);
1279 char *s = NULL;
1280 int c = *(arg + 3);
1281 int level;
1282
1283 if (len != 4 || !isdigit(c))
1284 error(arg);
1285
1286 level = atoi(arg + 3);
1287 if (level > 5)
1288 error(arg);
1289 if (level >= 2) {
1290 /*
1291 * For gcc-3.4.x at -O2 we
1292 * need to disable optimizations
1293 * that break ON.
1294 */
1295 optim_disable(ctx->i_ae, level);
1296 /*
1297 * limit -xO3 to -O2 as well.
1298 */
1299 level = 2;
1300 }
1301 if (asprintf(&s, "-O%d", level) == -1)
1302 nomem();
1303 newae(ctx->i_ae, s);
1304 free(s);
1305 break;
1306 }
1307 error(arg);
1308 break;
1309 case 'p':
1310 if (strcmp(arg, "-xpentium") == 0) {
1311 newae(ctx->i_ae, "-march=pentium");
1312 break;
1313 }
1314 if (strcmp(arg, "-xpg") == 0) {
1315 newae(ctx->i_ae, "-pg");
1316 break;
1317 }
1318 error(arg);
1319 break;
1320 case 'r':
1321 if (strncmp(arg, "-xregs=", 7) == 0) {
1322 xlate(ctx->i_ae, arg + 7, xregs_tbl);
1323 break;
1324 }
1325 error(arg);
1326 break;
1327 case 's':
1328 if (strcmp(arg, "-xs") == 0 ||
1329 strcmp(arg, "-xspace") == 0 ||
1330 strcmp(arg, "-xstrconst") == 0)
1331 break;
1332 error(arg);
1333 break;
1334 case 't':
1335 if (strcmp(arg, "-xtransition") == 0) {
1336 newae(ctx->i_ae, "-Wtransition");
1337 break;
1338 }
1339 if (strcmp(arg, "-xtrigraphs=yes") == 0) {
1340 newae(ctx->i_ae, "-trigraphs");
1341 break;
1342 }
1343 if (strcmp(arg, "-xtrigraphs=no") == 0) {
1344 newae(ctx->i_ae, "-notrigraphs");
1345 break;
1346 }
1347 if (strncmp(arg, "-xtarget=", 9) == 0) {
1348 xlate(ctx->i_ae, arg + 9, xtarget_tbl);
1349 break;
1350 }
1351 error(arg);
1352 break;
1353 case 'e':
1354 case 'h':
1355 case 'l':
1356 default:
1357 error(arg);
1358 break;
1359 }
1360 break;
1361 case 'Y':
1362 if (arglen == 1) {
1363 if ((arg = *++ctx->i_oldargv) == NULL ||
1364 *arg == '\0')
1365 error("-Y");
1366 ctx->i_oldargc--;
|
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2018, Richard Lowe.
25 */
26 /*
27 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 /*
32 * Wrapper for the GNU C compiler to make it accept the Sun C compiler
33 * arguments where possible.
34 *
35 * Since the translation is inexact, this is something of a work-in-progress.
36 *
37 */
38
39 /* If you modify this file, you must increment CW_VERSION */
40 #define CW_VERSION "3.0"
41
42 /*
43 * -# Verbose mode
44 * -### Show compiler commands built by driver, no compilation
45 * -A<name[(tokens)]> Preprocessor predicate assertion
46 * -B<[static|dynamic]> Specify dynamic or static binding
47 * -C Prevent preprocessor from removing comments
48 * -c Compile only - produce .o files, suppress linking
49 * -cg92 Alias for -xtarget=ss1000
50 * -D<name[=token]> Associate name with token as if by #define
51 * -d[y|n] dynamic [-dy] or static [-dn] option to linker
52 * -E Compile source through preprocessor only, output to stdout
53 * -erroff=<t> Suppress warnings specified by tags t(%none, %all, <tag list>)
54 * -errtags=<a> Display messages with tags a(no, yes)
55 * -errwarn=<t> Treats warnings specified by tags t(%none, %all, <tag list>)
56 * as errors
57 * -fast Optimize using a selection of options
58 * -fd Report old-style function definitions and declarations
59 * -fnonstd Initialize floating-point hardware to non-standard preferences
60 * -fns[=<yes|no>] Select non-standard floating point mode
61 * -fprecision=<p> Set FP rounding precision mode p(single, double, extended)
62 * -fround=<r> Select the IEEE rounding mode in effect at startup
63 * -fsimple[=<n>] Select floating-point optimization preferences <n>
64 * -fsingle Use single-precision arithmetic (-Xt and -Xs modes only)
65 * -ftrap=<t> Select floating-point trapping mode in effect at startup
66 * -fstore force floating pt. values to target precision on assignment
67 * -G Build a dynamic shared library
68 * -g Compile for debugging
69 * -H Print path name of each file included during compilation
70 * -h <name> Assign <name> to generated dynamic shared library
71 * -I<dir> Add <dir> to preprocessor #include file search path
72 * -i Passed to linker to ignore any LD_LIBRARY_PATH setting
73 * -keeptmp Keep temporary files created during compilation
74 * -KPIC Compile position independent code with 32-bit addresses
75 * -Kpic Compile position independent code
76 * -L<dir> Pass to linker to add <dir> to the library search path
77 * -l<name> Link with library lib<name>.a or lib<name>.so
78 * -mc Remove duplicate strings from .comment section of output files
79 * -mr Remove all strings from .comment section of output files
80 * -mr,"string" Remove all strings and append "string" to .comment section
81 * -mt Specify options needed when compiling multi-threaded code
82 * -native Find available processor, generate code accordingly
83 * -nofstore Do not force floating pt. values to target precision
84 * on assignment
85 * -norunpath Do not build in a runtime path for shared libraries
86 * -O Use default optimization level (-xO2 or -xO3. Check man page.)
87 * -o <outputfile> Set name of output file to <outputfile>
88 * -P Compile source through preprocessor only, output to .i file
89 * -p Compile for profiling with prof
90 * -Q[y|n] Emit/don't emit identification info to output file
91 * -R<dir[:dir]> Build runtime search path list into executable
92 * -S Compile and only generate assembly code (.s)
93 * -s Strip symbol table from the executable file
94 * -t Turn off duplicate symbol warnings when linking
95 * -U<name> Delete initial definition of preprocessor symbol <name>
96 * -V Report version number of each compilation phase
97 * -v Do stricter semantic checking
98 * -W<c>,<arg> Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
99 * -w Suppress compiler warning messages
100 * -Xa Compile assuming ANSI C conformance, allow K & R extensions
101 * (default mode)
102 * -Xs Compile assuming (pre-ANSI) K & R C style code
103 * -Xt Compile assuming K & R conformance, allow ANSI C
104 * -xarch=<a> Specify target architecture instruction set
105 * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
106 * for system functions, b={%all,%none}
107 * -xCC Accept C++ style comments
108 * -xchip=<c> Specify the target processor for use by the optimizer
109 * -xcode=<c> Generate different code for forming addresses
110 * -xcrossfile[=<n>] Enable optimization and inlining across source files,
111 * n={0|1}
112 * -xe Perform only syntax/semantic checking, no code generation
113 * -xF Compile for later mapfile reordering or unused section
114 * elimination
115 * -xhelp=<f> Display on-line help information f(flags, readme, errors)
116 * -xildoff Cancel -xildon
117 * -xildon Enable use of the incremental linker, ild
118 * -xinline=[<a>,...,<a>] Attempt inlining of specified user routines,
119 * <a>={%auto,func,no%func}
120 * -xlibmieee Force IEEE 754 return values for math routines in
121 * exceptional cases
122 * -xlibmil Inline selected libm math routines for optimization
123 * -xlic_lib=sunperf Link in the Sun supplied performance libraries
124 * -xlicinfo Show license server information
125 * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
126 * -xO<n> Generate optimized code (n={1|2|3|4|5})
127 * -xP Print prototypes for function definitions
128 * -xprofile=<p> Collect data for a profile or use a profile to optimize
129 * <p>={{collect,use}[:<path>],tcov}
130 * -xregs=<r> Control register allocation
131 * -xs Allow debugging without object (.o) files
132 * -xsb Compile for use with the WorkShop source browser
133 * -xsbfast Generate only WorkShop source browser info, no compilation
134 * -xsfpconst Represent unsuffixed floating point constants as single
135 * precision
136 * -xspace Do not do optimizations that increase code size
137 * -xstrconst Place string literals into read-only data segment
138 * -xtarget=<t> Specify target system for optimization
139 * -xtemp=<dir> Set directory for temporary files to <dir>
140 * -xtime Report the execution time for each compilation phase
141 * -xunroll=n Enable unrolling loops n times where possible
142 * -Y<c>,<dir> Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
143 * -YA,<dir> Change default directory searched for components
144 * -YI,<dir> Change default directory searched for include files
145 * -YP,<dir> Change default directory for finding libraries files
146 * -YS,<dir> Change default directory for startup object files
147 */
148
149 /*
150 * Translation table:
151 */
152 /*
153 * -# -v
154 * -### error
155 * -A<name[(tokens)]> pass-thru
156 * -B<[static|dynamic]> pass-thru (syntax error for anything else)
157 * -C pass-thru
158 * -c pass-thru
159 * -cg92 -m32 -mcpu=v8 -mtune=supersparc (SPARC only)
160 * -D<name[=token]> pass-thru
161 * -dy or -dn -Wl,-dy or -Wl,-dn
162 * -E pass-thru
163 * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
164 * -errtags=%all -Wall
165 * -errwarn=%all -Werror else -Wno-error
166 * -fast error
167 * -fd error
168 * -fnonstd error
169 * -fns[=<yes|no>] error
170 * -fprecision=<p> error
171 * -fround=<r> error
172 * -fsimple[=<n>] error
173 * -fsingle[=<n>] error
174 * -ftrap=<t> error
175 * -fstore error
176 * -G pass-thru
177 * -g pass-thru
178 * -H pass-thru
179 * -h <name> pass-thru
180 * -I<dir> pass-thru
181 * -i pass-thru
182 * -keeptmp -save-temps
183 * -KPIC -fPIC
184 * -Kpic -fpic
185 * -L<dir> pass-thru
186 * -l<name> pass-thru
187 * -mc error
188 * -mr error
189 * -mr,"string" error
190 * -mt -D_REENTRANT
191 * -native error
192 * -nofstore error
193 * -nolib -nodefaultlibs
194 * -norunpath ignore
195 * -O -O1 (Check the man page to be certain)
196 * -o <outputfile> pass-thru
197 * -P -E -o filename.i (or error)
198 * -p pass-thru
199 * -Q[y|n] error
200 * -R<dir[:dir]> pass-thru
201 * -S pass-thru
202 * -s -Wl,-s
203 * -t -Wl,-t
204 * -U<name> pass-thru
205 * -V --version
206 * -v -Wall
207 * -Wa,<arg> pass-thru
208 * -Wp,<arg> pass-thru except -xc99=<a>
209 * -Wl,<arg> pass-thru
210 * -W{m,0,2,h,i,u> error/ignore
211 * -xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone
212 * -Wu,-save_args -msave-args
213 * -w pass-thru
214 * -Xa -std=iso9899:199409 or -ansi
215 * -Xt error
216 * -Xs -traditional -std=c89
217 * -xarch=<a> table
218 * -xbuiltin[=<b>] -fbuiltin (-fno-builtin otherwise)
219 * -xCC ignore
220 * -xchip=<c> table
221 * -xcode=<c> table
222 * -xdebugformat=<format> ignore (always use dwarf-2 for gcc)
223 * -xcrossfile[=<n>] ignore
224 * -xe error
225 * -xF error
226 * -xhelp=<f> error
227 * -xildoff ignore
228 * -xildon ignore
229 * -xinline ignore
230 * -xlibmieee error
231 * -xlibmil error
232 * -xlic_lib=sunperf error
233 * -xmaxopt=[...] error
234 * -xO<n> -O<n>
235 * -xP error
236 * -xprofile=<p> error
237 * -xregs=<r> table
238 * -xs error
239 * -xsb error
240 * -xsbfast error
241 * -xsfpconst error
242 * -xspace ignore (-not -Os)
243 * -xstrconst ignore
244 * -xtarget=<t> table
245 * -xtemp=<dir> error
246 * -xtime error
247 * -xtransition -Wtransition
248 * -xunroll=n error
249 * -W0,-xdbggen=no%usedonly -fno-eliminate-unused-debug-symbols
250 * -fno-eliminate-unused-debug-types
251 * -Y<c>,<dir> error
252 * -YA,<dir> error
253 * -YI,<dir> -nostdinc -I<dir>
254 * -YP,<dir> error
255 * -YS,<dir> error
256 */
257
258 #include <ctype.h>
259 #include <err.h>
260 #include <errno.h>
261 #include <fcntl.h>
262 #include <getopt.h>
263 #include <stdio.h>
264 #include <stdlib.h>
265 #include <string.h>
266 #include <unistd.h>
267
473 newae(h, "-Wextra");
474 }
475
476 static void
477 optim_disable(struct aelist *h, int level)
478 {
479 if (level >= 2) {
480 newae(h, "-fno-strict-aliasing");
481 newae(h, "-fno-unit-at-a-time");
482 newae(h, "-fno-optimize-sibling-calls");
483 }
484 }
485
486 /* ARGSUSED */
487 static void
488 Xamode(struct aelist __unused *h)
489 {
490 }
491
492 static void
493 Xsmode(struct aelist *h)
494 {
495 static int xsonce;
496
497 if (xsonce++)
498 return;
499
500 newae(h, "-traditional");
501 newae(h, "-traditional-cpp");
502 }
503
504 static void
505 usage()
506 {
507 extern char *__progname;
508 (void) fprintf(stderr,
509 "usage: %s [-C] [--versions] --primary <compiler> "
510 "[--shadow <compiler>]... -- cflags...\n",
511 __progname);
512 (void) fprintf(stderr, "compilers take the form: name,path,style\n"
653 newae(ctx->i_ae, strchr(arg, '=') + 1);
654 continue;
655 }
656 if (strncmp(arg, "-compat=", 8) == 0) {
657 /* discard -compat=4 and -compat=5 */
658 continue;
659 }
660 if (strcmp(arg, "-Qoption") == 0) {
661 /* discard -Qoption and its two arguments */
662 if (ctx->i_oldargc < 3)
663 error(arg);
664 ctx->i_oldargc -= 2;
665 ctx->i_oldargv += 2;
666 continue;
667 }
668 if (strcmp(arg, "-xwe") == 0) {
669 /* turn warnings into errors */
670 newae(ctx->i_ae, "-Werror");
671 continue;
672 }
673 if (strcmp(arg, "-norunpath") == 0) {
674 /* gcc has no corresponding option */
675 continue;
676 }
677 if (strcmp(arg, "-nolib") == 0) {
678 /* -nodefaultlibs is on by default */
679 nolibc = 1;
680 continue;
681 }
682 #if defined(__sparc)
683 if (strcmp(arg, "-cg92") == 0) {
684 mflag |= xlate_xtb(ctx->i_ae, "v8");
685 xlate(ctx->i_ae, "super", xchip_tbl);
686 continue;
687 }
688 #endif /* __sparc */
689 }
690
691 switch ((c = arg[1])) {
692 case '_':
791 /*
792 * Accept but ignore this -- gcc doesn't
793 * seem to complain about empty translation
794 * units
795 */
796 break;
797 }
798 /* XX64 -- ignore all -erroff= options, for now */
799 if (strncmp(arg, "-erroff=", 8) == 0)
800 break;
801 if (strcmp(arg, "-errtags=yes") == 0) {
802 warnings(ctx->i_ae);
803 break;
804 }
805 if (strcmp(arg, "-errwarn=%all") == 0) {
806 newae(ctx->i_ae, "-Werror");
807 break;
808 }
809 error(arg);
810 break;
811 case 'G':
812 newae(ctx->i_ae, "-shared");
813 nolibc = 1;
814 break;
815 case 'k':
816 if (strcmp(arg, "-keeptmp") == 0) {
817 newae(ctx->i_ae, "-save-temps");
818 break;
819 }
820 error(arg);
821 break;
822 case 'K':
823 if (arglen == 1) {
824 if ((arg = *++ctx->i_oldargv) == NULL ||
825 *arg == '\0')
826 error("-K");
827 ctx->i_oldargc--;
828 } else {
829 arg += 2;
830 }
867 char *opt;
868 size_t len;
869 char *s;
870
871 if (arglen == 1) {
872 opt = *++ctx->i_oldargv;
873 if (opt == NULL || *opt == '\0')
874 error(arg);
875 ctx->i_oldargc--;
876 } else {
877 opt = arg + 2;
878 }
879 len = strlen(opt) + 7;
880 if ((s = malloc(len)) == NULL)
881 nomem();
882 (void) snprintf(s, len, "-Wl,-%c%s", c, opt);
883 newae(ctx->i_ae, s);
884 free(s);
885 }
886 break;
887 case 'O':
888 if (arglen == 1) {
889 newae(ctx->i_ae, "-O");
890 break;
891 }
892 error(arg);
893 break;
894 case 'P':
895 /*
896 * We could do '-E -o filename.i', but that's hard,
897 * and we don't need it for the case that's triggering
898 * this addition. We'll require the user to specify
899 * -o in the Makefile. If they don't they'll find out
900 * in a hurry.
901 */
902 newae(ctx->i_ae, "-E");
903 op = CW_O_PREPROCESS;
904 nolibc = 1;
905 break;
906 case 's':
907 if (arglen == 1) {
908 newae(ctx->i_ae, "-Wl,-s");
909 break;
910 }
911 error(arg);
912 break;
913 case 't':
914 if (arglen == 1) {
915 newae(ctx->i_ae, "-Wl,-t");
916 break;
917 }
918 error(arg);
919 break;
920 case 'V':
921 if (arglen == 1) {
922 ctx->i_flags &= ~CW_F_ECHO;
923 newae(ctx->i_ae, "--version");
924 break;
925 }
929 if (arglen == 1) {
930 warnings(ctx->i_ae);
931 break;
932 }
933 error(arg);
934 break;
935 case 'W':
936 if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
937 /*
938 * gcc's preprocessor will accept c99
939 * regardless, so accept and ignore.
940 */
941 break;
942 }
943 if (strncmp(arg, "-Wa,", 4) == 0 ||
944 strncmp(arg, "-Wp,", 4) == 0 ||
945 strncmp(arg, "-Wl,", 4) == 0) {
946 newae(ctx->i_ae, arg);
947 break;
948 }
949 if (strcmp(arg, "-W0,-noglobal") == 0 ||
950 strcmp(arg, "-W0,-xglobalstatic") == 0) {
951 /*
952 * gcc doesn't prefix local symbols
953 * in debug mode, so this is not needed.
954 */
955 break;
956 }
957 if (strcmp(arg, "-W0,-Lt") == 0) {
958 /*
959 * Generate tests at the top of loops.
960 * There is no direct gcc equivalent, ignore.
961 */
962 break;
963 }
964 if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) {
965 newae(ctx->i_ae,
966 "-fno-eliminate-unused-debug-symbols");
967 newae(ctx->i_ae,
968 "-fno-eliminate-unused-debug-types");
969 break;
970 }
971 if (strcmp(arg, "-W2,-xwrap_int") == 0) {
972 /*
973 * Use the legacy behaviour (pre-SS11)
974 * for integer wrapping.
975 * gcc does not need this.
976 */
977 break;
978 }
979 if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
980 /*
981 * Prevents optimizing away checks for
982 * unbound weak symbol addresses. gcc does
983 * not do this, so it's not needed.
984 */
985 break;
986 }
987 if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
988 xlate(ctx->i_ae, arg + 11, xcode_tbl);
989 if (strncmp(arg + 11, "pic", 3) == 0)
990 pic = 1;
991 break;
992 }
993 if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
994 /*
995 * Prevents insertion of register symbols.
996 * gcc doesn't do this, so ignore it.
997 */
998 break;
999 }
1000 if (strcmp(arg, "-Wc,-Qassembler-ounrefsym=0") == 0) {
1001 /*
1002 * Prevents optimizing away of static variables.
1003 * gcc does not do this, so it's not needed.
1004 */
1005 break;
1006 }
1007 #if defined(__x86)
1008 if (strcmp(arg, "-Wu,-save_args") == 0) {
1009 newae(ctx->i_ae, "-msave-args");
1010 break;
1011 }
1012 #endif /* __x86 */
1013 error(arg);
1014 break;
1015 case 'X':
1016 if (strcmp(arg, "-Xa") == 0 ||
1017 strcmp(arg, "-Xt") == 0) {
1018 Xamode(ctx->i_ae);
1019 break;
1020 }
1021 if (strcmp(arg, "-Xs") == 0) {
1022 Xsmode(ctx->i_ae);
1023 break;
1024 }
1025 error(arg);
1026 break;
1027 case 'x':
1028 if (arglen == 1)
1029 error(arg);
1030 switch (arg[2]) {
1031 case 'a':
1032 if (strncmp(arg, "-xarch=", 7) == 0) {
1033 mflag |= xlate_xtb(ctx->i_ae, arg + 7);
1034 break;
1035 }
1036 error(arg);
1037 break;
1038 case 'b':
1039 if (strncmp(arg, "-xbuiltin=", 10) == 0) {
1040 if (strcmp(arg + 10, "%all"))
1041 newae(ctx->i_ae, "-fbuiltin");
1042 break;
1043 }
1044 error(arg);
1045 break;
1046 case 'C':
1047 /* Accept C++ style comments -- ignore */
1048 if (strcmp(arg, "-xCC") == 0)
1049 break;
1050 error(arg);
1051 break;
1052 case 'c':
1053 if (strncmp(arg, "-xc99=%all", 10) == 0) {
1054 newae(ctx->i_ae, "-std=gnu99");
1055 break;
1056 }
1057 if (strncmp(arg, "-xc99=%none", 11) == 0) {
1058 newae(ctx->i_ae, "-std=gnu89");
1059 break;
1060 }
1061 if (strncmp(arg, "-xchip=", 7) == 0) {
1062 xlate(ctx->i_ae, arg + 7, xchip_tbl);
1063 break;
1064 }
1065 if (strncmp(arg, "-xcode=", 7) == 0) {
1066 xlate(ctx->i_ae, arg + 7, xcode_tbl);
1067 if (strncmp(arg + 7, "pic", 3) == 0)
1068 pic = 1;
1069 break;
1070 }
1071 if (strncmp(arg, "-xcrossfile", 11) == 0)
1072 break;
1073 error(arg);
1074 break;
1075 case 'd':
1076 if (strncmp(arg, "-xdebugformat=", 14) == 0)
1077 break;
1078 error(arg);
1079 break;
1080 case 'F':
1081 /*
1082 * Compile for mapfile reordering, or unused
1083 * section elimination, syntax can be -xF or
1084 * more complex, like -xF=%all -- ignore.
1085 */
1086 if (strncmp(arg, "-xF", 3) == 0)
1087 break;
1088 error(arg);
1089 break;
1090 case 'i':
1091 if (strncmp(arg, "-xinline", 8) == 0)
1092 /* No inlining; ignore */
1093 break;
1094 if (strcmp(arg, "-xildon") == 0 ||
1095 strcmp(arg, "-xildoff") == 0)
1096 /* No incremental linking; ignore */
1097 break;
1098 error(arg);
1099 break;
1100 #if defined(__x86)
1101 case 'm':
1102 if (strcmp(arg, "-xmodel=kernel") == 0) {
1103 newae(ctx->i_ae, "-ffreestanding");
1104 newae(ctx->i_ae, "-mno-red-zone");
1105 model = "-mcmodel=kernel";
1106 nolibc = 1;
1107 break;
1108 }
1109 error(arg);
1110 break;
1111 #endif /* __x86 */
1112 case 'O':
1113 if (strncmp(arg, "-xO", 3) == 0) {
1114 size_t len = strlen(arg);
1115 char *s = NULL;
1116 int c = *(arg + 3);
1117 int level;
1118
1119 if (len != 4 || !isdigit(c))
1120 error(arg);
1121
1122 level = atoi(arg + 3);
1123 if (level > 5)
1124 error(arg);
1125 if (level >= 2) {
1126 /*
1127 * For gcc-3.4.x at -O2 we
1128 * need to disable optimizations
1129 * that break ON.
1130 */
1131 optim_disable(ctx->i_ae, level);
1132 /*
1133 * limit -xO3 to -O2 as well.
1134 */
1135 level = 2;
1136 }
1137 if (asprintf(&s, "-O%d", level) == -1)
1138 nomem();
1139 newae(ctx->i_ae, s);
1140 free(s);
1141 break;
1142 }
1143 error(arg);
1144 break;
1145 case 'r':
1146 if (strncmp(arg, "-xregs=", 7) == 0) {
1147 xlate(ctx->i_ae, arg + 7, xregs_tbl);
1148 break;
1149 }
1150 error(arg);
1151 break;
1152 case 's':
1153 if (strcmp(arg, "-xs") == 0 ||
1154 strcmp(arg, "-xspace") == 0 ||
1155 strcmp(arg, "-xstrconst") == 0)
1156 break;
1157 error(arg);
1158 break;
1159 case 't':
1160 if (strncmp(arg, "-xtarget=", 9) == 0) {
1161 xlate(ctx->i_ae, arg + 9, xtarget_tbl);
1162 break;
1163 }
1164 error(arg);
1165 break;
1166 case 'e':
1167 case 'h':
1168 case 'l':
1169 default:
1170 error(arg);
1171 break;
1172 }
1173 break;
1174 case 'Y':
1175 if (arglen == 1) {
1176 if ((arg = *++ctx->i_oldargv) == NULL ||
1177 *arg == '\0')
1178 error("-Y");
1179 ctx->i_oldargc--;
|