Print this page
libm fixes from richlowe - richlowe.net/webrevs/il_keith
patch01 - 693 import Sun Devpro Math Library
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/aw/aw.c
+++ new/usr/src/tools/aw/aw.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Wrapper for the GNU assembler to make it accept the Sun assembler
29 29 * arguments where possible.
30 30 *
31 31 * There are several limitations; the Sun assembler takes multiple
32 32 * source files, we only take one.
33 33 *
34 34 * -b, -s, -xF, -T plain not supported.
35 35 * -S isn't supported either, because while GNU as does generate
36 36 * listings with -a, there's no obvious mapping between sub-options.
37 37 * -K pic, -K PIC not supported either, though it's not clear what
38 38 * these actually do ..
39 39 * -Qy (not supported) adds a string to the .comment section
40 40 * describing the assembler version, while
41 41 * -Qn (supported) suppresses the string (also the default).
42 42 *
43 43 * We also add '-#' support to see invocation lines..
44 44 * We also add '-xarch=amd64' in case we need to feed the assembler
45 45 * something different (or in case we need to invoke a different binary
46 46 * altogether!)
47 47 */
48 48
49 49 #include <sys/types.h>
50 50 #include <sys/wait.h>
51 51 #include <stdio.h>
52 52 #include <unistd.h>
53 53 #include <string.h>
54 54 #include <stdlib.h>
55 55 #include <sys/param.h>
56 56
57 57 static const char *progname;
58 58 static int verbose;
59 59
60 60 struct aelist {
61 61 int ael_argc;
62 62 struct ae {
63 63 struct ae *ae_next;
64 64 char *ae_arg;
65 65 } *ael_head, *ael_tail;
66 66 };
67 67
68 68 static struct aelist *
69 69 newael(void)
70 70 {
71 71 return (calloc(sizeof (struct aelist), 1));
72 72 }
73 73
74 74 static void
75 75 newae(struct aelist *ael, const char *arg)
76 76 {
77 77 struct ae *ae;
78 78
79 79 ae = calloc(sizeof (*ae), 1);
80 80 ae->ae_arg = strdup(arg);
81 81 if (ael->ael_tail == NULL)
82 82 ael->ael_head = ae;
83 83 else
84 84 ael->ael_tail->ae_next = ae;
85 85 ael->ael_tail = ae;
86 86 ael->ael_argc++;
87 87 }
88 88
89 89 static void
90 90 fixae_arg(struct ae *ae, const char *newarg)
91 91 {
92 92 free(ae->ae_arg);
93 93 ae->ae_arg = strdup(newarg);
94 94 }
95 95
96 96 static char **
97 97 aeltoargv(struct aelist *ael)
98 98 {
99 99 struct ae *ae;
100 100 char **argv;
101 101 int argc;
102 102
103 103 argv = calloc(sizeof (*argv), ael->ael_argc + 1);
104 104
105 105 for (argc = 0, ae = ael->ael_head; ae; ae = ae->ae_next, argc++) {
106 106 argv[argc] = ae->ae_arg;
107 107 if (ae == ael->ael_tail)
108 108 break;
109 109 }
110 110
111 111 return (argv);
112 112 }
113 113
114 114 static int
115 115 error(const char *arg)
116 116 {
117 117 (void) fprintf(stderr,
118 118 "%s: as->gas mapping failed at or near arg '%s'\n", progname, arg);
119 119 return (2);
120 120 }
121 121
122 122 static int
123 123 usage(const char *arg)
124 124 {
125 125 if (arg != NULL)
126 126 (void) fprintf(stderr, "error: %s\n", arg);
127 127 (void) fprintf(stderr, "Usage: %s [-V] [-#]\n"
128 128 "\t[-xarch=architecture]\n"
129 129 "\t[-o objfile] [-L]\n"
130 130 "\t[-P [[-Ipath] [-Dname] [-Dname=def] [-Uname]]...]\n"
131 131 "\t[-m] [-n] file.s ...\n", progname);
132 132 return (3);
133 133 }
134 134
135 135 static void
136 136 copyuntil(FILE *in, FILE *out, int termchar)
137 137 {
138 138 int c;
139 139
140 140 while ((c = fgetc(in)) != EOF) {
141 141 if (out && fputc(c, out) == EOF)
142 142 exit(1);
143 143 if (c == termchar)
144 144 break;
145 145 }
146 146 }
147 147
148 148 /*
149 149 * Variant of copyuntil(), used for copying the path used
150 150 * for .file directives. This version removes the workspace
151 151 * from the head of the path, or failing that, attempts to remove
152 152 * /usr/include. This is a workaround for the way gas handles
153 153 * these directives. The objects produced by gas contain STT_FILE
154 154 * symbols for every .file directive. These FILE symbols contain our
155 155 * workspace paths, leading to wsdiff incorrectly flagging them as
156 156 * having changed. By clipping off the workspace from these paths,
157 157 * we eliminate these false positives.
158 158 */
159 159 static void
160 160 copyuntil_path(FILE *in, FILE *out, int termchar,
161 161 const char *wspace, size_t wspace_len)
162 162 {
163 163 #define PROTO_INC "/proto/root_i386/usr/include/"
164 164 #define SYS_INC "/usr/include/"
165 165
166 166 static const size_t proto_inc_len = sizeof (PROTO_INC) - 1;
167 167 static const size_t sys_inc_len = sizeof (SYS_INC) - 1;
168 168
169 169 /*
170 170 * Dynamically sized buffer for reading paths. Retained
171 171 * and reused between calls.
172 172 */
173 173 static char *buf = NULL;
174 174 static size_t bufsize = 0;
175 175
176 176 size_t bufcnt = 0;
177 177 char *bufptr;
178 178 int c;
179 179
180 180 /* Read the path into the buffer */
181 181 while ((c = fgetc(in)) != EOF) {
182 182 /*
183 183 * If we need a buffer, or need a larger buffer,
184 184 * fix that here.
185 185 */
186 186 if (bufcnt >= bufsize) {
187 187 bufsize = (bufsize == 0) ? MAXPATHLEN : (bufsize * 2);
188 188 buf = realloc(buf, bufsize + 1); /* + room for NULL */
189 189 if (buf == NULL) {
190 190 perror("realloc");
191 191 exit(1);
192 192 }
193 193 }
194 194
195 195 buf[bufcnt++] = c;
196 196 if (c == termchar)
197 197 break;
198 198 }
199 199 if (bufcnt == 0)
200 200 return;
201 201
202 202 /*
203 203 * We have a non-empty buffer, and thus the opportunity
204 204 * to do some surgery on it before passing it to the output.
205 205 */
206 206 buf[bufcnt] = '\0';
207 207 bufptr = buf;
208 208
209 209 /*
210 210 * If our workspace is at the start, remove it.
211 211 * If not, then look for the system /usr/include instead.
212 212 */
213 213 if ((wspace_len > 0) && (wspace_len < bufcnt) &&
214 214 (strncmp(bufptr, wspace, wspace_len) == 0)) {
215 215 bufptr += wspace_len;
216 216 bufcnt -= wspace_len;
217 217
218 218 /*
219 219 * Further opportunity: Also clip the prefix
220 220 * that leads to /usr/include in the proto.
221 221 */
222 222 if ((proto_inc_len < bufcnt) &&
223 223 (strncmp(bufptr, PROTO_INC, proto_inc_len) == 0)) {
224 224 bufptr += proto_inc_len;
225 225 bufcnt -= proto_inc_len;
226 226 }
227 227 } else if ((sys_inc_len < bufcnt) &&
228 228 (strncmp(bufptr, SYS_INC, sys_inc_len) == 0)) {
229 229 bufptr += sys_inc_len;
230 230 bufcnt -= sys_inc_len;
231 231 }
232 232
233 233 /* Output whatever is left */
234 234 if (out && (fwrite(bufptr, 1, bufcnt, out) != bufcnt)) {
235 235 perror("fwrite");
236 236 exit(1);
237 237 }
238 238
239 239 #undef PROTO_INC
240 240 #undef SYS_INC
241 241 }
242 242
243 243 /*
244 244 * The idea here is to take directives like this emitted
245 245 * by cpp:
246 246 *
247 247 * # num
248 248 *
249 249 * and convert them to directives like this that are
250 250 * understood by the GNU assembler:
251 251 *
252 252 * .line num
253 253 *
254 254 * and similarly:
255 255 *
256 256 * # num "string" optional stuff
257 257 *
258 258 * is converted to
259 259 *
260 260 * .line num
261 261 * .file "string"
262 262 *
263 263 * While this could be done with a sequence of sed
264 264 * commands, this is simpler and faster..
265 265 */
266 266 static pid_t
267 267 filter(int pipein, int pipeout)
268 268 {
269 269 pid_t pid;
270 270 FILE *in, *out;
271 271 char *wspace;
272 272 size_t wspace_len;
273 273
274 274 if (verbose)
275 275 (void) fprintf(stderr, "{#line filter} ");
276 276
277 277 switch (pid = fork()) {
278 278 case 0:
279 279 if (dup2(pipein, 0) == -1 ||
280 280 dup2(pipeout, 1) == -1) {
281 281 perror("dup2");
282 282 exit(1);
283 283 }
284 284 closefrom(3);
285 285 break;
286 286 case -1:
287 287 perror("fork");
288 288 default:
289 289 return (pid);
290 290 }
291 291
292 292 in = fdopen(0, "r");
293 293 out = fdopen(1, "w");
294 294
295 295 /*
296 296 * Key off the CODEMGR_WS environment variable to detect
297 297 * if we're in an activated workspace, and to get the
298 298 * path to the workspace.
299 299 */
300 300 wspace = getenv("CODEMGR_WS");
301 301 if (wspace != NULL)
302 302 wspace_len = strlen(wspace);
303 303
304 304 while (!feof(in)) {
305 305 int c, num;
306 306
307 307 switch (c = fgetc(in)) {
308 308 case '#':
309 309 switch (fscanf(in, " %d", &num)) {
310 310 case 0:
311 311 /*
312 312 * discard comment lines completely
313 313 * discard ident strings completely too.
314 314 * (GNU as politely ignores them..)
315 315 */
316 316 copyuntil(in, NULL, '\n');
317 317 break;
318 318 default:
319 319 (void) fprintf(stderr, "fscanf botch?");
320 320 /*FALLTHROUGH*/
321 321 case EOF:
322 322 exit(1);
323 323 /*NOTREACHED*/
324 324 case 1:
325 325 /*
326 326 * This line has a number at the beginning;
327 327 * if it has a string after the number, then
328 328 * it's a filename.
329 329 *
330 330 * If this is an activated workspace, use
331 331 * copyuntil_path() to do path rewriting
332 332 * that will prevent workspace paths from
333 333 * being burned into the resulting object.
334 334 * If not in an activated workspace, then
335 335 * copy the existing path straight through
336 336 * without interpretation.
337 337 */
338 338 if (fgetc(in) == ' ' && fgetc(in) == '"') {
339 339 (void) fprintf(out, "\t.file \"");
340 340 if (wspace != NULL)
341 341 copyuntil_path(in, out, '"',
342 342 wspace, wspace_len);
343 343 else
344 344 copyuntil(in, out, '"');
345 345 (void) fputc('\n', out);
346 346 }
347 347 (void) fprintf(out, "\t.line %d\n", num - 1);
348 348 /*
349 349 * discard the rest of the line
350 350 */
351 351 copyuntil(in, NULL, '\n');
352 352 break;
353 353 }
354 354 break;
355 355 case '\n':
356 356 /*
357 357 * preserve newlines
358 358 */
359 359 (void) fputc(c, out);
360 360 break;
361 361 case EOF:
362 362 /*
363 363 * don't write EOF!
364 364 */
365 365 break;
366 366 default:
367 367 /*
368 368 * lines that don't begin with '#' are copied
369 369 */
370 370 (void) fputc(c, out);
371 371 copyuntil(in, out, '\n');
372 372 break;
373 373 }
374 374
375 375 if (ferror(out))
376 376 exit(1);
377 377 }
378 378
379 379 exit(0);
380 380 /*NOTREACHED*/
381 381 }
382 382
383 383 static pid_t
384 384 invoke(char **argv, int pipein, int pipeout)
385 385 {
386 386 pid_t pid;
387 387
388 388 if (verbose) {
389 389 char **dargv = argv;
390 390
391 391 while (*dargv)
392 392 (void) fprintf(stderr, "%s ", *dargv++);
393 393 }
394 394
395 395 switch (pid = fork()) {
396 396 case 0:
397 397 if (pipein >= 0 && dup2(pipein, 0) == -1) {
398 398 perror("dup2");
399 399 exit(1);
400 400 }
401 401 if (pipeout >= 0 && dup2(pipeout, 1) == -1) {
402 402 perror("dup2");
403 403 exit(1);
404 404 }
405 405 closefrom(3);
406 406 (void) execvp(argv[0], argv);
407 407 perror("execvp");
408 408 (void) fprintf(stderr, "%s: couldn't run %s\n",
409 409 progname, argv[0]);
410 410 break;
411 411 case -1:
412 412 perror("fork");
413 413 default:
414 414 return (pid);
415 415 }
416 416 exit(2);
417 417 /*NOTREACHED*/
418 418 }
419 419
420 420 static int
421 421 pipeline(char **ppargv, char **asargv)
422 422 {
423 423 int pipedes[4];
424 424 int active = 0;
425 425 int rval = 0;
426 426 pid_t pid_pp, pid_f, pid_as;
427 427
428 428 if (pipe(pipedes) == -1 || pipe(pipedes + 2) == -1) {
429 429 perror("pipe");
430 430 return (4);
431 431 }
432 432
433 433 if ((pid_pp = invoke(ppargv, -1, pipedes[0])) > 0)
434 434 active++;
435 435
436 436 if (verbose)
437 437 (void) fprintf(stderr, "| ");
438 438
439 439 if ((pid_f = filter(pipedes[1], pipedes[2])) > 0)
440 440 active++;
441 441
442 442 if (verbose)
443 443 (void) fprintf(stderr, "| ");
444 444
445 445 if ((pid_as = invoke(asargv, pipedes[3], -1)) > 0)
446 446 active++;
447 447
448 448 if (verbose) {
449 449 (void) fprintf(stderr, "\n");
450 450 (void) fflush(stderr);
451 451 }
452 452
453 453 closefrom(3);
454 454
455 455 if (active != 3)
456 456 return (5);
457 457
458 458 while (active != 0) {
459 459 pid_t pid;
460 460 int stat;
461 461
462 462 if ((pid = wait(&stat)) == -1) {
463 463 rval++;
464 464 break;
465 465 }
466 466
467 467 if (!WIFEXITED(stat))
468 468 continue;
469 469
470 470 if (pid == pid_pp || pid == pid_f || pid == pid_as) {
471 471 active--;
472 472 if (WEXITSTATUS(stat) != 0)
473 473 rval++;
474 474 }
475 475 }
476 476
477 477 return (rval);
478 478 }
479 479
480 480 int
481 481 main(int argc, char *argv[])
482 482 {
483 483 struct aelist *cpp = NULL;
484 484 struct aelist *m4 = NULL;
485 485 struct aelist *as = newael();
486 486 char **asargv;
487 487 char *outfile = NULL;
488 488 char *srcfile = NULL;
489 489 const char *dir, *cmd;
490 490 static char as_pgm[MAXPATHLEN];
491 491 static char as64_pgm[MAXPATHLEN];
492 492 static char m4_pgm[MAXPATHLEN];
493 493 static char m4_cmdefs[MAXPATHLEN];
494 494 static char cpp_pgm[MAXPATHLEN];
495 495 int as64 = 0;
496 496 int code;
497 497
498 498 if ((progname = strrchr(argv[0], '/')) == NULL)
499 499 progname = argv[0];
500 500 else
501 501 progname++;
502 502
503 503 /*
504 504 * Helpful when debugging, or when changing tool versions..
505 505 */
506 506 if ((cmd = getenv("AW_AS")) != NULL)
507 507 strlcpy(as_pgm, cmd, sizeof (as_pgm));
508 508 else {
509 509 if ((dir = getenv("AW_AS_DIR")) == NULL)
510 510 dir = DEFAULT_AS_DIR; /* /usr/sfw/bin */
511 511 (void) snprintf(as_pgm, sizeof (as_pgm), "%s/gas", dir);
512 512 }
513 513
514 514 if ((cmd = getenv("AW_AS64")) != NULL)
515 515 strlcpy(as64_pgm, cmd, sizeof (as64_pgm));
516 516 else {
517 517 if ((dir = getenv("AW_AS64_DIR")) == NULL)
518 518 dir = DEFAULT_AS64_DIR; /* /usr/sfw/bin */
519 519 (void) snprintf(as64_pgm, sizeof (as_pgm), "%s/gas", dir);
520 520 }
521 521
522 522 if ((cmd = getenv("AW_M4")) != NULL)
523 523 strlcpy(m4_pgm, cmd, sizeof (m4_pgm));
524 524 else {
525 525 if ((dir = getenv("AW_M4_DIR")) == NULL)
526 526 dir = DEFAULT_M4_DIR; /* /usr/ccs/bin */
527 527 (void) snprintf(m4_pgm, sizeof (m4_pgm), "%s/m4", dir);
528 528 }
529 529
530 530 if ((cmd = getenv("AW_M4LIB")) != NULL)
531 531 strlcpy(m4_cmdefs, cmd, sizeof (m4_cmdefs));
532 532 else {
533 533 if ((dir = getenv("AW_M4LIB_DIR")) == NULL)
534 534 dir = DEFAULT_M4LIB_DIR; /* /usr/ccs/lib */
535 535 (void) snprintf(m4_cmdefs, sizeof (m4_cmdefs),
536 536 "%s/cm4defs", dir);
537 537 }
538 538
539 539 if ((cmd = getenv("AW_CPP")) != NULL)
540 540 strlcpy(cpp_pgm, cmd, sizeof (cpp_pgm));
541 541 else {
542 542 if ((dir = getenv("AW_CPP_DIR")) == NULL)
543 543 dir = DEFAULT_CPP_DIR; /* /usr/ccs/lib */
544 544 (void) snprintf(cpp_pgm, sizeof (cpp_pgm), "%s/cpp", dir);
545 545 }
546 546
547 547 newae(as, as_pgm);
548 548 newae(as, "--warn");
549 549 newae(as, "--fatal-warnings");
550 550 newae(as, "--traditional-format");
551 551
552 552 /*
553 553 * Walk the argument list, translating as we go ..
554 554 */
555 555 while (--argc > 0) {
556 556 char *arg;
557 557 int arglen;
558 558
559 559 arg = *++argv;
560 560 arglen = strlen(arg);
561 561
562 562 if (*arg != '-') {
563 563 char *filename;
↓ open down ↓ |
563 lines elided |
↑ open up ↑ |
564 564
565 565 /*
566 566 * filenames ending in '.s' are taken to be
567 567 * assembler files, and provide the default
568 568 * basename of the output file.
569 569 *
570 570 * other files are passed through to the
571 571 * preprocessor, if present, or to gas if not.
572 572 */
573 573 filename = arg;
574 - if (arglen > 2 &&
575 - strcmp(arg + arglen - 2, ".s") == 0) {
574 + if ((arglen > 2) &&
575 + ((strcmp(arg + arglen - 2, ".s") == 0) ||
576 + (strcmp(arg + arglen - 2, ".S") == 0))) {
576 577 /*
577 578 * Though 'as' allows multiple assembler
578 579 * files to be processed in one invocation
579 580 * of the assembler, ON only processes one
580 581 * file at a time, which makes things a lot
581 582 * simpler!
582 583 */
583 584 if (srcfile == NULL)
584 585 srcfile = arg;
585 586 else
586 587 return (usage(
587 588 "one assembler file at a time"));
588 589
589 590 /*
590 591 * If we haven't seen a -o option yet,
591 592 * default the output to the basename
592 593 * of the input, substituting a .o on the end
593 594 */
594 595 if (outfile == NULL) {
595 596 char *argcopy;
596 597
597 598 argcopy = strdup(arg);
598 599 argcopy[arglen - 1] = 'o';
599 600
600 601 if ((outfile = strrchr(
601 602 argcopy, '/')) == NULL)
602 603 outfile = argcopy;
603 604 else
604 605 outfile++;
605 606 }
606 607 }
607 608 if (cpp)
608 609 newae(cpp, filename);
609 610 else if (m4)
610 611 newae(m4, filename);
611 612 else
612 613 newae(as, filename);
613 614 continue;
614 615 } else
615 616 arglen--;
616 617
617 618 switch (arg[1]) {
618 619 case 'K':
619 620 /*
620 621 * -K pic
621 622 * -K PIC
622 623 */
623 624 if (arglen == 1) {
624 625 if ((arg = *++argv) == NULL || *arg == '\0')
625 626 return (usage("malformed -K"));
626 627 argc--;
627 628 } else {
628 629 arg += 2;
629 630 }
630 631 if (strcmp(arg, "PIC") != 0 && strcmp(arg, "pic") != 0)
631 632 return (usage("malformed -K"));
632 633 break; /* just ignore -Kpic for gcc */
633 634 case 'Q':
634 635 if (strcmp(arg, "-Qn") == 0)
635 636 break;
636 637 /*FALLTHROUGH*/
637 638 case 'b':
638 639 case 's':
639 640 case 'T':
640 641 /*
641 642 * -b Extra symbol table for source browser ..
642 643 * not relevant to gas, thus should error.
643 644 * -s Put stabs in .stabs section not stabs.excl
644 645 * not clear if there's an equivalent
645 646 * -T 4.x migration option
646 647 */
647 648 default:
648 649 return (error(arg));
649 650 case 'x':
650 651 /*
651 652 * Accept -xarch special case to invoke alternate
652 653 * assemblers or assembler flags for different
653 654 * architectures.
654 655 */
655 656 if (strcmp(arg, "-xarch=amd64") == 0 ||
656 657 strcmp(arg, "-xarch=generic64") == 0) {
657 658 as64++;
658 659 fixae_arg(as->ael_head, as64_pgm);
659 660 break;
660 661 }
661 662 /*
662 663 * XX64: Is this useful to gas?
663 664 */
664 665 if (strcmp(arg, "-xmodel=kernel") == 0)
665 666 break;
666 667
667 668 /*
668 669 * -xF Generates performance analysis data
669 670 * no equivalent
670 671 */
671 672 return (error(arg));
672 673 case 'V':
673 674 newae(as, arg);
674 675 break;
675 676 case '#':
676 677 verbose++;
677 678 break;
678 679 case 'L':
679 680 newae(as, "--keep-locals");
680 681 break;
681 682 case 'n':
682 683 newae(as, "--no-warn");
683 684 break;
684 685 case 'o':
685 686 if (arglen != 1)
686 687 return (usage("bad -o flag"));
687 688 if ((arg = *++argv) == NULL || *arg == '\0')
688 689 return (usage("bad -o flag"));
689 690 outfile = arg;
690 691 argc--;
691 692 arglen = strlen(arg + 1);
692 693 break;
693 694 case 'm':
694 695 if (cpp)
695 696 return (usage("-m conflicts with -P"));
696 697 if (m4 == NULL) {
697 698 m4 = newael();
698 699 newae(m4, m4_pgm);
699 700 newae(m4, m4_cmdefs);
700 701 }
701 702 break;
702 703 case 'P':
703 704 if (m4)
704 705 return (usage("-P conflicts with -m"));
705 706 if (cpp == NULL) {
706 707 cpp = newael();
707 708 newae(cpp, cpp_pgm);
708 709 newae(cpp, "-D__GNUC_AS__");
709 710 }
710 711 break;
711 712 case 'D':
712 713 case 'U':
713 714 if (cpp)
714 715 newae(cpp, arg);
715 716 else if (m4)
716 717 newae(m4, arg);
717 718 else
718 719 newae(as, arg);
719 720 break;
720 721 case 'I':
721 722 if (cpp)
722 723 newae(cpp, arg);
723 724 else
724 725 newae(as, arg);
725 726 break;
726 727 case '-': /* a gas-specific option */
727 728 newae(as, arg);
728 729 break;
729 730 }
730 731 }
731 732
732 733 #if defined(__i386)
733 734 if (as64)
734 735 newae(as, "--64");
735 736 else
736 737 newae(as, "--32");
737 738 #endif
738 739
739 740 if (srcfile == NULL)
740 741 return (usage("no source file(s) specified"));
741 742 if (outfile == NULL)
742 743 outfile = "a.out";
743 744 newae(as, "-o");
744 745 newae(as, outfile);
745 746
746 747 asargv = aeltoargv(as);
747 748 if (cpp) {
748 749 #if defined(__sparc)
749 750 newae(cpp, "-Dsparc");
750 751 newae(cpp, "-D__sparc");
751 752 if (as64)
752 753 newae(cpp, "-D__sparcv9");
753 754 else
754 755 newae(cpp, "-D__sparcv8");
755 756 #elif defined(__i386) || defined(__x86)
756 757 if (as64) {
757 758 newae(cpp, "-D__x86_64");
758 759 newae(cpp, "-D__amd64");
759 760 } else {
760 761 newae(cpp, "-Di386");
761 762 newae(cpp, "-D__i386");
762 763 }
763 764 #else
764 765 #error "need isa-dependent defines"
765 766 #endif
766 767 code = pipeline(aeltoargv(cpp), asargv);
767 768 } else if (m4)
768 769 code = pipeline(aeltoargv(m4), asargv);
769 770 else {
770 771 /*
771 772 * XXX should arrange to fork/exec so that we
772 773 * can unlink the output file if errors are
773 774 * detected..
774 775 */
775 776 (void) execvp(asargv[0], asargv);
776 777 perror("execvp");
777 778 (void) fprintf(stderr, "%s: couldn't run %s\n",
778 779 progname, asargv[0]);
779 780 code = 7;
780 781 }
781 782 if (code != 0)
782 783 (void) unlink(outfile);
783 784 return (code);
784 785 }
↓ open down ↓ |
199 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX