Print this page
5196 The cw wrapper restricts gcc to -O2


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*


  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Wrapper for the GNU C compiler to make it accept the Sun C compiler
  29  * arguments where possible.
  30  *
  31  * Since the translation is inexact, this is something of a work-in-progress.
  32  *
  33  */
  34 
  35 /* If you modify this file, you must increment CW_VERSION */
  36 #define CW_VERSION      "1.29"
  37 
  38 /*
  39  * -#           Verbose mode
  40  * -###         Show compiler commands built by driver, no compilation
  41  * -A<name[(tokens)]>     Preprocessor predicate assertion
  42  * -B<[static|dynamic]>   Specify dynamic or static binding
  43  * -C           Prevent preprocessor from removing comments
  44  * -c           Compile only - produce .o files, suppress linking
  45  * -cg92        Alias for -xtarget=ss1000
  46  * -D<name[=token]>       Associate name with token as if by #define
  47  * -d[y|n]      dynamic [-dy] or static [-dn] option to linker
  48  * -E           Compile source through preprocessor only, output to stdout
  49  * -erroff=<t>    Suppress warnings specified by tags t(%none, %all, <tag list>)
  50  * -errtags=<a>   Display messages with tags a(no, yes)
  51  * -errwarn=<t>   Treats warnings specified by tags t(%none, %all, <tag list>)
  52  *              as errors
  53  * -fast        Optimize using a selection of options
  54  * -fd          Report old-style function definitions and declarations
  55  * -features=zla        Allow zero-length arrays
  56  * -flags       Show this summary of compiler options


 517 
 518 /*
 519  * Add the current favourite set of warnings to the gcc invocation.
 520  */
 521 static void
 522 warnings(struct aelist *h)
 523 {
 524         static int warningsonce;
 525 
 526         if (warningsonce++)
 527                 return;
 528 
 529         /*
 530          * Enable as many warnings as exist, then disable those that we never
 531          * ever want.
 532          */
 533         newae(h, "-Wall");
 534         newae(h, "-Wextra");
 535 }
 536 
 537 static void
 538 optim_disable(struct aelist *h, int level)
 539 {
 540         if (level >= 2) {
 541                 newae(h, "-fno-strict-aliasing");
 542                 newae(h, "-fno-unit-at-a-time");
 543                 newae(h, "-fno-optimize-sibling-calls");
 544         }
 545 }
 546 
 547 /* ARGSUSED */
 548 static void
 549 Xamode(struct aelist *h)
 550 {
 551 }
 552 
 553 static void
 554 Xcmode(struct aelist *h)
 555 {
 556         static int xconce;
 557 
 558         if (xconce++)
 559                 return;
 560 
 561         newae(h, "-ansi");
 562         newae(h, "-pedantic-errors");
 563 }
 564 
 565 static void
 566 Xsmode(struct aelist *h)


1288                                         break;
1289                                 }
1290                                 error(arg);
1291                                 break;
1292                         case 'O':
1293                                 if (strncmp(arg, "-xO", 3) == 0) {
1294                                         size_t len = strlen(arg);
1295                                         char *s;
1296                                         int c = *(arg + 3);
1297                                         int level;
1298 
1299                                         if (len != 4 || !isdigit(c))
1300                                                 error(arg);
1301 
1302                                         if ((s = malloc(len)) == NULL)
1303                                                 nomem();
1304 
1305                                         level = atoi(arg + 3);
1306                                         if (level > 5)
1307                                                 error(arg);
1308                                         if (level >= 2) {
1309                                                 /*
1310                                                  * For gcc-3.4.x at -O2 we
1311                                                  * need to disable optimizations
1312                                                  * that break ON.
1313                                                  */
1314                                                 optim_disable(ctx->i_ae, level);
1315                                                 /*
1316                                                  * limit -xO3 to -O2 as well.
1317                                                  */
1318                                                 level = 2;
1319                                         }
1320                                         (void) snprintf(s, len, "-O%d", level);
1321                                         newae(ctx->i_ae, s);
1322                                         free(s);
1323                                         break;
1324                                 }
1325                                 error(arg);
1326                                 break;
1327                         case 'p':
1328                                 if (strcmp(arg, "-xpentium") == 0) {
1329                                         newae(ctx->i_ae, "-march=pentium");
1330                                         break;
1331                                 }
1332                                 if (strcmp(arg, "-xpg") == 0) {
1333                                         newae(ctx->i_ae, "-pg");
1334                                         break;
1335                                 }
1336                                 error(arg);
1337                                 break;
1338                         case 'r':
1339                                 if (strncmp(arg, "-xregs=", 7) == 0) {




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2014 Gary Mills
  24  *
  25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 /*
  30  * Wrapper for the GNU C compiler to make it accept the Sun C compiler
  31  * arguments where possible.
  32  *
  33  * Since the translation is inexact, this is something of a work-in-progress.
  34  *
  35  */
  36 
  37 /* If you modify this file, you must increment CW_VERSION */
  38 #define CW_VERSION      "1.30"
  39 
  40 /*
  41  * -#           Verbose mode
  42  * -###         Show compiler commands built by driver, no compilation
  43  * -A<name[(tokens)]>     Preprocessor predicate assertion
  44  * -B<[static|dynamic]>   Specify dynamic or static binding
  45  * -C           Prevent preprocessor from removing comments
  46  * -c           Compile only - produce .o files, suppress linking
  47  * -cg92        Alias for -xtarget=ss1000
  48  * -D<name[=token]>       Associate name with token as if by #define
  49  * -d[y|n]      dynamic [-dy] or static [-dn] option to linker
  50  * -E           Compile source through preprocessor only, output to stdout
  51  * -erroff=<t>    Suppress warnings specified by tags t(%none, %all, <tag list>)
  52  * -errtags=<a>   Display messages with tags a(no, yes)
  53  * -errwarn=<t>   Treats warnings specified by tags t(%none, %all, <tag list>)
  54  *              as errors
  55  * -fast        Optimize using a selection of options
  56  * -fd          Report old-style function definitions and declarations
  57  * -features=zla        Allow zero-length arrays
  58  * -flags       Show this summary of compiler options


 519 
 520 /*
 521  * Add the current favourite set of warnings to the gcc invocation.
 522  */
 523 static void
 524 warnings(struct aelist *h)
 525 {
 526         static int warningsonce;
 527 
 528         if (warningsonce++)
 529                 return;
 530 
 531         /*
 532          * Enable as many warnings as exist, then disable those that we never
 533          * ever want.
 534          */
 535         newae(h, "-Wall");
 536         newae(h, "-Wextra");
 537 }
 538 










 539 /* ARGSUSED */
 540 static void
 541 Xamode(struct aelist *h)
 542 {
 543 }
 544 
 545 static void
 546 Xcmode(struct aelist *h)
 547 {
 548         static int xconce;
 549 
 550         if (xconce++)
 551                 return;
 552 
 553         newae(h, "-ansi");
 554         newae(h, "-pedantic-errors");
 555 }
 556 
 557 static void
 558 Xsmode(struct aelist *h)


1280                                         break;
1281                                 }
1282                                 error(arg);
1283                                 break;
1284                         case 'O':
1285                                 if (strncmp(arg, "-xO", 3) == 0) {
1286                                         size_t len = strlen(arg);
1287                                         char *s;
1288                                         int c = *(arg + 3);
1289                                         int level;
1290 
1291                                         if (len != 4 || !isdigit(c))
1292                                                 error(arg);
1293 
1294                                         if ((s = malloc(len)) == NULL)
1295                                                 nomem();
1296 
1297                                         level = atoi(arg + 3);
1298                                         if (level > 5)
1299                                                 error(arg);












1300                                         (void) snprintf(s, len, "-O%d", level);
1301                                         newae(ctx->i_ae, s);
1302                                         free(s);
1303                                         break;
1304                                 }
1305                                 error(arg);
1306                                 break;
1307                         case 'p':
1308                                 if (strcmp(arg, "-xpentium") == 0) {
1309                                         newae(ctx->i_ae, "-march=pentium");
1310                                         break;
1311                                 }
1312                                 if (strcmp(arg, "-xpg") == 0) {
1313                                         newae(ctx->i_ae, "-pg");
1314                                         break;
1315                                 }
1316                                 error(arg);
1317                                 break;
1318                         case 'r':
1319                                 if (strncmp(arg, "-xregs=", 7) == 0) {