コード例 #1
0
ファイル: lang_defs.c プロジェクト: prabindh/openuh
/* return path and name of phase */
char *
get_full_phase_name (phases_t index)
{
	buffer_t tmp;
	strcpy(tmp, get_phase_dir(index));
	strcat(tmp, "/");
	return concat_strings (tmp, get_phase_name(index));
}
コード例 #2
0
ファイル: objects.c プロジェクト: qiyao/xcc
extern void
append_libraries_to_list (string_list_t *list)
{
        string_item_t *p;
        for (p = library_dirs->head; p != NULL; p = p->next) {
		add_string(list, concat_strings("-L", p->name));
        }
        /*
         * get_phase_dir(P_library) is not in library_dirs because
         * library_dirs is also used as the search path for the crt file
         */
        if (!option_was_seen(O_L)) {
                add_string(list,
                           concat_strings("-L", get_phase_dir(P_library)));
        }
}
コード例 #3
0
ファイル: lang_defs.c プロジェクト: manojxantony/compiler
/* return path and name of phase */
char *
get_full_phase_name (phases_t index)
{
	buffer_t tmp;
	strcpy(tmp, get_phase_dir(index));
	if (strlen(tmp) > 0) {
	    strcat(tmp, "/");
	}
	if (sizeof(EXT_EXE) > 1) {
	    strcat(tmp, get_phase_name(index));
	    return concat_strings (tmp, EXT_EXE);
	}
	else {
	    return concat_strings (tmp, get_phase_name(index));
	}
}
コード例 #4
0
ファイル: license.c プロジェクト: Akheon23/nvopencc
void obtain_license (char *exedir, int argc, char *argv[]) {
    int pipes[2] ;
    int pid ;
    char exename[MAXPATHLEN] ;
    char language[10] ;
    struct stat st ;
    int i ;
    char *l ;

    const char *errortext = "Unable to obtain subscription.  The PathScale compiler cannot run without a subscription.\nPlease see http://www.pathscale.com/subscription/1.1/msgs.html for details.\n" ;
   
    l = getenv ("PATHSCALE_SUBSCRIPTION_CLIENT") ;
    if (l == NULL) {
        snprintf (exename, sizeof(exename), "%s/subclient", exedir) ;
        if (subverbose) {
            fprintf (stderr, "Subscription client: looking for %s\n", exename) ;
        }
        if (stat (exename, &st) != 0) {
            snprintf (exename, sizeof(exename), "%s/subclient",
		      get_phase_dir(P_be)) ;
            if (subverbose) {
                fprintf (stderr, "Subscription client: looking for %s\n", exename) ;
            }
            if (stat (exename, &st) != 0) {
                fprintf (stderr, errortext) ;
                do_exit (1); 
            }
        }
    } else {
        strcpy (exename, l) ;
        if (subverbose) {
            fprintf (stderr, "Subscription client: looking for %s\n", exename) ;
        }
        if (stat (exename, &st) != 0) {
            fprintf (stderr, errortext) ;
            do_exit (1); 
        }
    }

    subflags[0] = '\0' ;
    for (i = 1 ; i < argc ; i++) {
        if (argv[i][0] == '-') {
            switch (argv[i][1]) {
            case 'o':		// don't pass these as they might contain sensitive stuff
            case 'I':
            case 'L':
            case 'D':
            case 'U':
                break ;
            case 'W':
                if (strncmp (argv[i], "-Wl", 3) == 0) {
                }
                goto addflag ;
            case 'T':
                if (strncmp (argv[i], "-TENV:ipa_ident", 15) == 0) {
                    break ;
                }
                // fall through
            default:
            addflag:
                strcat (subflags, argv[i]) ;
                strcat (subflags, " ") ;
                break ;
            }
        }
    }

    switch (invoked_lang) {
    case L_f77:
        strcpy (language, "FORTRAN77") ;
	break;
    case L_f90:
        strcpy (language, "FORTRAN90") ;
	break;
    case L_cc:
        strcpy (language, "C") ;
	break;
    case L_CC:
        strcpy (language, "CC") ;
	break;
    }

    pid = fork() ;
    if (pid == 0) {		// child
        const char *argvec[8] ;

        argvec[0] = exename ;
        argvec[1] = "Compiler" ;
        argvec[2] = language ;
        argvec[3] = OPEN64_BUILD_DATE ;
        argvec[4] = subflags ;
        argvec[5] = OPEN64_FULL_VERSION ;
        argvec[6] = NULL ;
        if (subverbose) {
            argvec[6] = "--v" ;
            argvec[7] = NULL ;
        }
        execv (exename, (char*const*)argvec) ;
        fprintf (stderr, errortext) ;
        do_exit (6) ;
    } else {
        int statloc ;
        waitpid (pid, &statloc, 0) ;

        // if we were not able to get a license due to missing subclient executable, tell caller
        if (WIFEXITED(statloc)) {
            if (WEXITSTATUS (statloc) == 6) {		// no subclient program?
                do_exit (1) ;
            } else if (WEXITSTATUS (statloc) == 7) {	// hard stop?
                fprintf (stderr, "Compilation terminated\n") ;
                do_exit (1) ;
            } else if (WEXITSTATUS (statloc) != 0) {            // license client failed, can't rely on output
                fprintf (stderr, "Subscription client exited with error status\n") ;
                do_exit (1) ;
            }
        }

    }
}
コード例 #5
0
void
run_phase (phases_t phase, char *name, string_list_t *args)
{
	char **argv;
	int argc = 1;
	string_item_t *p;
	char *output = NULL;
	char *input = NULL;
	boolean save_stderr = FALSE;
	int fdin, fdout;
	int forkpid;
	int waitpid;
	int waitstatus;
	int termsig;
	int	num_maps;
	char *rld_path, *absoft_path;
	struct stat stat_buf;
	const boolean uses_message_system = 
			(phase == P_f90_fe || phase == P_f90_cpp ||
			 phase == P_cppf90_fe);

#if defined(__APPLE__)
        // pass -Wa,-W to assembler so we ignore unknowns
        int hack_as_W = 0;
        if (strcmp(name, "/usr/bin/gcc") == 0)
        {
                hack_as_W = 1;
		argc++;
        }
#endif

	if (show_flag) {
		/* echo the command */
		fprintf(stderr, "%s ", name);
		print_string_list(stderr, args);
	}
	if (!execute_flag) return;

	if (time_flag) init_time();

	/* copy arg_list to argv format that exec wants */
	for (p = args->head; p != NULL; p=p->next) {
		//bug# 581, bug #932, bug #1049
		if (p->name == NULL) 
                  continue;
		argc++;
	}

	argv = (char **) malloc((argc+1)*sizeof(char*));
	argv[0] = name;
	for (argc = 1, p = args->head; p != NULL; argc++, p=p->next) {
		//bug# 581, bug #932
		if (p->name[0] == '\0') {
		  argc--;
                  continue;
		}
		/* don't put redirection in arg list */
		if (strcmp(p->name, "<") == 0) {
			/* has input file */
			input = p->next->name;
			break;
		} else if (strcmp(p->name, ">") == 0) {
			/* has output file */
			output = p->next->name;
			break;
		} else if (strcmp(p->name, ">&") == 0) {
			/* has error output file */
			output = p->next->name;
			save_stderr = TRUE;
			break;
		}
		argv[argc] = p->name;
	}
#if defined(__APPLE__)
	if (hack_as_W)
	{
#ifndef Is_True_On
		argv[argc++] = ""; // "-Wa,-W";
#endif
	}
#endif
	argv[argc] = NULL;

	/* fork a process */
	forkpid = fork();
	if (forkpid == -1) {
		error("no more processes");
		cleanup ();
		do_exit (RC_SYSTEM_ERROR);
		/* NOTREACHED */
	}

	if (forkpid == 0) {
		char *my_path, *l_path, *l32_path, *nls_path, *env_path;
		
		/* child */
		/* if we want memory stats, we have to wait for
		   parent to connect to our /proc */
		if (input != NULL) {
			if ((fdin = open (input, O_RDONLY)) == -1) {
				error ("cannot open input file %s", input);
				cleanup ();
				do_exit (RC_SYSTEM_ERROR);
				/* NOTREACHED */
			}
	    		dup2 (fdin, fileno(stdin));
		}
		if (output != NULL) {
			if ((fdout = creat (output, 0666)) == -1) {
				error ("cannot create output file %s", output);
				cleanup ();
				do_exit (RC_SYSTEM_ERROR);
				/* NOTREACHED */
			}
			if (save_stderr) {
	    			dup2 (fdout, fileno(stderr));
			} else {
	    			dup2 (fdout, fileno(stdout));
			}
		} 

		my_path = get_binutils_lib_path();
		rld_path = get_phase_ld_library_path (phase);
		absoft_path = get_absoft_ld_library_path (phase);
		
		if (absoft_path != 0)
			asprintf(&my_path, "%s:%s", my_path, absoft_path);

		if (rld_path != 0)
			asprintf(&my_path, "%s:%s", my_path, rld_path);
		
		l_path = l32_path = my_path;
		
		if (ld_library_path)
			asprintf(&l_path, "%s:%s", my_path, ld_library_path);

		if (ld_libraryn32_path)
			asprintf(&l32_path, "%s:%s", my_path,
				 ld_libraryn32_path);

		my_putenv("LD_LIBRARY_PATH", l_path);
		my_putenv("LD_LIBRARYN32_PATH", l32_path);
		
		// Set up NLSPATH, for the Fortran front end.

		nls_path = getenv("NLSPATH");
		env_path = get_phase_dir(P_f90_fe);

		if (nls_path) {
		    my_putenv("NLSPATH", "%s:%s/%%N.cat", nls_path, env_path);
		} else {
		    my_putenv("NLSPATH", "%s/%%N.cat", env_path);
		}

		if (uses_message_system && getenv("ORIG_CMD_NAME") == NULL)
		   my_putenv("ORIG_CMD_NAME", "%s", program_name);

		if (phase == P_f90_fe) {
		   char *root;
		   char *modulepath;
		   int len;
		   char *new_env;
		   char *env_name = "FORTRAN_SYSTEM_MODULES=";
		   char *env_val = "/usr/lib/f90modules";
		   root = getenv("TOOLROOT");
		   if (root != NULL) {
		      len = strlen(env_val) + strlen(root) +3 + strlen(env_val);
		      new_env = alloca(len);
		      sprintf(new_env,"%s/%s:%s",root,env_val,env_val);
		      env_val = new_env;
		   }
		   modulepath = string_copy(getenv("FORTRAN_SYSTEM_MODULES"));
		   if (modulepath != NULL) {
		      /* Append env_val to FORTRAN_SYSTEM_MODULES */
		      if (modulepath[strlen(modulepath)-1] == ':') {
			 /* Just append env_val */
			 len = strlen(modulepath) + strlen(env_val) + 1;
			 new_env = alloca(len);
			 sprintf(new_env,"%s%s",modulepath,env_val);
		      } else {
			 /* append :env_val */
			 len = strlen(modulepath) + strlen(env_val) + 2;
			 new_env = alloca(len);
			 sprintf(new_env,"%s:%s",modulepath,env_val);
		      }
		      env_val = new_env;
		   }
		   
		   my_putenv ("FORTRAN_SYSTEM_MODULES", "%s", env_val);
		}
		/* need to setenv COMPILER_PATH for collect to find ld */
		my_putenv ("COMPILER_PATH", "%s", get_phase_dir(P_collect));

		/* Tell IPA where to find the driver. */
#if defined(ABSOFT_EXTENSIONS)
		my_putenv ("COMPILER_BIN", "%s/" PSC_NAME_PREFIX "f90",
				get_executable_dir());
#else
		my_putenv ("COMPILER_BIN", "%s/" PSC_NAME_PREFIX "cc-"
			   PSC_FULL_VERSION, get_executable_dir());
#endif

		my_execv(name, argv);
	} else {
		/* parent */
		int procid;	/* id of the /proc file */
		while ((waitpid = wait (&waitstatus)) != forkpid) {
			if (waitpid == -1) {
				error("bad return from wait");
				cleanup();
				do_exit(RC_SYSTEM_ERROR);
				/* NOTREACHED */
			}
		}
		if (time_flag) print_time(name);

		if (WIFSTOPPED(waitstatus)) {
			termsig = WSTOPSIG(waitstatus);
			error("STOPPED signal received from %s", name);
			cleanup();
			do_exit(RC_SYSTEM_ERROR);
			/* NOTREACHED */
		} else if (WIFEXITED(waitstatus)) {
		        int status = WEXITSTATUS(waitstatus);
			extern int inline_t;
			boolean internal_err = FALSE;
			boolean user_err = FALSE;
		
			if (phase == P_prof) {
                           /* Make sure the .cfb files were created before
                              changing the STATUS to OKAY */
                           if (prof_file != NULL) {
                              if (!(stat(fb_file, &stat_buf) != 0 && errno == ENOENT))
                                  status = RC_OKAY;
                           } else {
			      internal_error("No count file was specified for a prof run");
			      perror(program_name);
                           }
                        }

			if (phase == P_f90_fe && keep_listing) {
			    char *cif_file;
			    cif_file = construct_given_name(
					  drop_path(source_file), "T", TRUE);
                            if (!(stat(cif_file, &stat_buf) != 0 && errno == ENOENT))
			       f90_fe_status = status;
			       f90_fe_name = string_copy(name);

			       /* Change the status to OKAY so that we can 
				* execute the lister on the cif_file; we will
				* take appropriate action on this status once 
				* the lister has finished executing. See below.
				*/

			       status = RC_OKAY;
                        }

			if (phase == P_lister) {
			   if (status == RC_OKAY && f90_fe_status != RC_OKAY) {

			      /* We had encountered an error in the F90_fe phase
			       * but we ignored it so that we could execute the
			       * lister on the cif file; we need to switch the
			       * status to the status we received from F90_fe
			       * and use the name of the F90_fe_phase, so that
			       * we can issue a correct error message.
			       */

			       status = f90_fe_status;
			       name = string_copy(f90_fe_name);

			       /* Reset f90_fe_status to OKAY for any further
				* compilations on other source files.
				*/

			       f90_fe_status = RC_OKAY;
                           }
                        }

			switch (status) {
			case RC_OKAY:
				if (inline_t == UNDEFINED
				    && is_matching_phase(
					get_phase_mask(phase), P_any_fe) )
				{
					inline_t = FALSE;
				}
				break;
			case RC_NEED_INLINER:
				if (inline_t == UNDEFINED
				    && is_matching_phase(
					get_phase_mask(phase), P_any_fe) )
				{
					inline_t = TRUE;
				}
				/* completed successfully */
				break;
				
			case RC_USER_ERROR:
			case RC_NORECOVER_USER_ERROR:
			case RC_SYSTEM_ERROR:
			case RC_GCC_ERROR:
				user_err = TRUE;
				break;

			case RC_OVERFLOW_ERROR:
				if (!ran_twice && phase == P_be) {
					/* try recompiling with larger limits */
					ran_twice = TRUE;
					add_string (args, "-TENV:long_eh_offsets");
					add_string (args, "-TENV:large_stack");
					run_phase (phase, name, args);
					return;
				}
				internal_err = TRUE;
				break;
			case RC_INTERNAL_ERROR:
				internal_err = TRUE;
				break;
			default:
				internal_err = TRUE;
				break;
			} 
			if (internal_err) {
				if (phase == P_ld || phase == P_ldplus ||
#ifdef KEY
				    phase == P_gas ||	// bug 4846
#endif
				    phase == P_gcpp || phase == P_gcpp_plus) {
					if (phase == P_gas)
						internal_error_occurred = 1;
					log_error("%s returned non-zero status %d",
						  name, status);
					nomsg_error(status);
				} else {
					internal_error("%s returned non-zero status %d",
						       name, status);
				}
			}
			else if (user_err) {
				/* assume phase will print diagnostics */
				if (phase == P_c_gfe || phase == P_cplus_gfe) {
					nomsg_error(RC_INTERNAL_ERROR);
				}
				else if (!show_flag || save_stderr) {
					nomsg_error(RC_USER_ERROR);
				} else {
					error("%s returned non-zero status %d",
						name, status);
				}
			}
			ran_twice = FALSE;
			return;
		} else if(WIFSIGNALED(waitstatus)){
			termsig = WTERMSIG(waitstatus);
			switch (termsig) {
			case SIGHUP:
			case SIGINT:
			case SIGQUIT:
			case SIGKILL:
			case SIGTERM:
				error("%s died due to signal %d", name, termsig);
				break;
			default:
				internal_error("%s died due to signal %d",
					       name, termsig);
				break;
			}
#ifndef __CYGWIN__
			if(waitstatus & WCOREFLAG) {
				error("core dumped");
			}
#endif
			if (termsig == SIGKILL) {
				error("Probably caused by running out of swap space -- check %s", LOGFILE);
			}
			cleanup();
			do_exit(RC_SYSTEM_ERROR);
		} else {
			/* cannot happen, I think! */
			internal_error("driver exec'ing is confused");
			return;
		}
	}
}
コード例 #6
0
void
run_phase (phases_t phase, char *name, string_list_t *args)
{
    const char **argv;
    int argc;
    string_item_t *p;
    char *output = NULL;
    char *input = NULL;
    boolean save_stderr = FALSE;
    int fdin, fdout;
    int waitstatus;
    int termsig;
    int num_maps;
    char *rld_path;
    struct stat stat_buf;
    const char* errmsg;
    int errnum;
    char *my_path;
    char *l_path;
    char *l32_path;
    char *nls_path;
    char *env_path;
    char *root_prefix;

#if defined(BUILD_OS_DARWIN)
    int suppress_compiler_path = (phase == P_gas);
#endif /* defined(BUILD_OS_DARWIN) */
    const boolean uses_message_system = 
            (phase == P_f90_fe || phase == P_cppf90_fe);

    if ((phase == P_be || phase == P_ipl) && add_heap_limit) {
        char str[200];

        sprintf(str, "-OPT:hugepage_heap_limit=%d -OPT:hugepage_attr=%d", 
			    heap_limit, hugepage_attr);
        add_string(args, str);
    }
    
    if (show_flag) {
        /* echo the command */
        fprintf(stderr, "%s ", name);
        print_string_list(stderr, args);
    }

    if (!execute_flag) return;

    if (time_flag) init_time();

    /* copy arg_list to argv format that exec wants */
    for (argc = 1, p = args->head; p != NULL; p = p->next) {
        //bug# 581, bug #932, bug #1049
        if (p->name == NULL || p->name[0] == '\0') {
            continue;
        }
        argc++;
    }
    argv = (const char **)malloc((argc + 1) * sizeof(char *));
    if (argv == NULL) {
        error("not enough memory");
        cleanup();
        do_exit(RC_SYSTEM_ERROR);
    }

    argv[0] = name;
    for (argc = 1, p = args->head; p != NULL; p = p->next) {
        //bug# 581, bug #932
        if (p->name == NULL || p->name[0] == '\0') {
            continue;
        }
        /* don't put redirection in arg list */
        if (strcmp(p->name, "<") == 0) {
            /* has input file */
            input = p->next->name;
            break;
        } else if (strcmp(p->name, ">") == 0) {
            /* has output file */
            output = p->next->name;
            break;
        } else if (strcmp(p->name, ">&") == 0) {
            /* has error output file */
            output = p->next->name;
            save_stderr = TRUE;
            break;
        }
        argv[argc++] = p->name;
    }
    argv[argc] = NULL;

    if (show_command_only(name, argv)) {
        return;
    }

    my_path = get_binutils_lib_path();
    rld_path = get_phase_ld_library_path(phase);
    
    if (rld_path != NULL) {
        asprintf(&my_path, "%s:%s", my_path, rld_path);
    }
    
    l_path = l32_path = my_path;
    
    if (ld_library_path) {
        asprintf(&l_path, "%s:%s", my_path, ld_library_path);
    }

    /* if we want memory stats, we have to wait for
       parent to connect to our /proc */
    if (input != NULL) {
    	if ((fdin = open (input, O_RDONLY)) == -1) {
            error ("cannot open input file %s", input);
            cleanup ();
            do_exit (RC_SYSTEM_ERROR);
            /* NOTREACHED */
    	}
    	dup2 (fdin, fileno(stdin));
    }
    if (output != NULL) {
    	if ((fdout = creat (output, 0666)) == -1) {
            error ("cannot create output file %s", output);
            cleanup ();
            do_exit (RC_SYSTEM_ERROR);
            /* NOTREACHED */
    	}
    	if (save_stderr) {
            dup2 (fdout, fileno(stderr));
    	} else {
            dup2 (fdout, fileno(stdout));
    	}
    } 
    
    my_path = get_binutils_lib_path();
    rld_path = get_phase_ld_library_path (phase);
    
    if (rld_path != 0) {
    	asprintf(&my_path, "%s:%s:%s/%s", my_path, rld_path, rld_path, current_target->abi_name);
    }
    
    l_path = l32_path = my_path;
    
    if (ld_library_path)
    	asprintf(&l_path, "%s:%s", my_path, ld_library_path);
    
    if (ld_libraryn32_path)
    	asprintf(&l32_path, "%s:%s", my_path,
    		 ld_libraryn32_path);

#if defined(BUILD_OS_DARWIN)
    /* Darwin static linker uses LD_LIBRARY_PATH, but dynamic
     * linker uses DYLD_LIBRARY_PATH */
    my_putenv("DYLD_LIBRARY_PATH", "%s", l_path);
#else /* defined(BUILD_OS_DARWIN) */
    my_putenv("LD_LIBRARY_PATH", "%s", l_path);
    my_putenv("LD_LIBRARYN32_PATH", "%s", l32_path);
#endif /* defined(BUILD_OS_DARWIN) */
		
    // Set up NLSPATH, for the Fortran front end.
    
    nls_path = getenv("NLSPATH");
    root_prefix = directory_path(get_executable_dir());
    
    if (nls_path) {
        my_putenv("NLSPATH", "%s:%s%s/%%N.cat", nls_path, root_prefix, LIBPATH);
    } else {
        my_putenv("NLSPATH", "%s%s/%%N.cat", root_prefix, LIBPATH);
    }
    
    if (uses_message_system && getenv("ORIG_CMD_NAME") == NULL)
        my_putenv("ORIG_CMD_NAME", "%s", program_name);
    
    if (phase == P_f90_fe) {
        char *root;
        char *modulepath;
        int len;
        char *new_env;
        char *env_name = "FORTRAN_SYSTEM_MODULES=";
        char *env_val = "/usr/lib/f90modules";
        root = getenv("TOOLROOT");
        if (root != NULL) {
            len = strlen(env_val) + strlen(root) +3 + strlen(env_val);
            new_env = alloca(len);
            sprintf(new_env,"%s/%s:%s",root,env_val,env_val);
            env_val = new_env;
        }
        modulepath = string_copy(getenv("FORTRAN_SYSTEM_MODULES"));
        if (modulepath != NULL) {
            /* Append env_val to FORTRAN_SYSTEM_MODULES */
            if (modulepath[strlen(modulepath)-1] == ':') {
                /* Just append env_val */
                len = strlen(modulepath) + strlen(env_val) + 1;
                new_env = alloca(len);
                sprintf(new_env,"%s%s",modulepath,env_val);
            } else {
                /* append :env_val */
                len = strlen(modulepath) + strlen(env_val) + 2;
                new_env = alloca(len);
                sprintf(new_env,"%s:%s",modulepath,env_val);
            }
            env_val = new_env;
        }
        
        my_putenv ("FORTRAN_SYSTEM_MODULES", "%s", env_val);
    }

    /* need to setenv COMPILER_PATH for collect to find ld */
    if (
#ifdef KEY
        // gcc will invoke the cc1 in the COMPILER_PATH directory,
        // which is not what we want when we invoke gcc for
        // preprocessing.  Bug 10164.

#if defined(BUILD_OS_DARWIN)
        /* Driver uses gcc to run assembler. If we set COMPILER_PATH,
         * gcc uses PSC version of cc1, which doesn't accept one of
         * the options (-mmacosx-version-min=10.5.1) which Apple's
         * gcc driver passes to Apple's cc1. Looks like the
         * "is_matching_phase" test might already be trying to fix
         * this, but it's not succeeding.
         */
        !suppress_compiler_path &&
#endif
        !is_matching_phase(get_phase_mask(P_any_cpp), phase) &&
#endif
        1) {
        my_putenv("COMPILER_PATH", "%s", get_phase_dir(P_collect));
    }

    /* Tell IPA where to find the driver. */
    my_putenv("COMPILER_BIN", "%s/" PSC_NAME_PREFIX "cc-"
              PSC_FULL_VERSION, get_executable_dir());

    if (execute(name, argv, input, output, &errmsg, &waitstatus) == -1) {
        error("execute failed: %s", errmsg);
        cleanup();
        do_exit(RC_SYSTEM_ERROR);
    }

    if (time_flag) print_time(name);
    
    if (WIFSTOPPED(waitstatus)) {
        error("STOPPED signal received from %s", name);
        cleanup();
        do_exit(RC_SYSTEM_ERROR);
        /* NOTREACHED */
    } else if (WIFEXITED(waitstatus)) {
        int status = WEXITSTATUS(waitstatus);
        extern int inline_t;
        boolean internal_err = FALSE;
        boolean user_err = FALSE;
        
        if (phase == P_prof) {
            /* Make sure the .cfb files were created before
               changing the STATUS to OKAY */
            if (prof_file != NULL) {
                if (!(stat(fb_file, &stat_buf) != 0 && errno == ENOENT)) {
                    status = RC_OKAY;
                }
            } else {
                internal_error("No count file was specified for a prof run");
                perror(program_name);
            }
        }
    
        if (phase == P_f90_fe && keep_listing) {
            char *cif_file = construct_given_name(drop_path(source_file), 
                                                  "T", TRUE);
    
            if (!(stat(cif_file, &stat_buf) != 0 && errno == ENOENT)) {
                f90_fe_status = status;
            }
            
            f90_fe_name = string_copy(name);
    
            /* Change the status to OKAY so that we can 
             * execute the lister on the cif_file; we will
             * take appropriate action on this status once 
             * the lister has finished executing. See below.
             */
            status = RC_OKAY;
        }
    
        if (phase == P_lister) {
            if (status == RC_OKAY && f90_fe_status != RC_OKAY) {
    
                /* We had encountered an error in the F90_fe phase
                 * but we ignored it so that we could execute the
                 * lister on the cif file; we need to switch the
                 * status to the status we received from F90_fe
                 * and use the name of the F90_fe_phase, so that
                 * we can issue a correct error message.
                 */
    
                status = f90_fe_status;
                name = string_copy(f90_fe_name);
    
                /* Reset f90_fe_status to OKAY for any further
                 * compilations on other source files.
                 */
    
                f90_fe_status = RC_OKAY;
            }
        }
    
        switch (status) {
        case RC_OKAY:
#ifdef KEY
            // If the command line has explicit inline
            // setting, follow it; else follow the
            // front-end request.  Bug 11325.
            if (inline_t != UNDEFINED) {
                run_inline = inline_t;
                break;
            }

#ifdef PATH64_ENABLE_GNU_FRONTEND
            // bug 10215
            if (is_matching_phase(get_phase_mask(phase), P_wgen)) {
              run_inline = FALSE;
            }
#endif // PATH64_ENABLE_GNU_FRONTEND
#ifdef PATH64_ENABLE_PSCLANG
            // bug 10215
            if (is_matching_phase(get_phase_mask(phase), P_psclang)) {
              run_inline = FALSE;
            }
#endif // PATH64_ENABLE_PSCLANG
            break;
#endif
            if (inline_t == UNDEFINED  && 
                is_matching_phase(get_phase_mask(phase), P_any_fe)) {
#ifdef KEY
                run_inline = FALSE; // bug 11325
#else
                inline_t = FALSE;
#endif
            }
            break;
        
        case RC_NEED_INLINER:
#ifdef KEY      // If the command line has explicit inline
            // setting, follow it; else follow the
            // front-end request.  Bug 11325.
            if (inline_t != UNDEFINED) {
                run_inline = inline_t;
                break;
            }

#ifdef PATH64_ENABLE_GNU_FRONTEND
            // bug 10215
            if (is_matching_phase(get_phase_mask(phase), P_wgen)) {
                run_inline = TRUE;
            }
#endif // PATH64_ENABLE_GNU_FRONTEND
#ifdef PATH64_ENABLE_PSCLANG
            // bug 10215
            if (is_matching_phase(get_phase_mask(phase), P_psclang)) {
              run_inline = TRUE;
            }
#endif // PATH64_ENABLE_PSCLANG
            break;

#endif
            if (inline_t == UNDEFINED && 
                is_matching_phase(get_phase_mask(phase), P_any_fe)) {
#ifdef KEY
                run_inline = TRUE;  // bug 11325
#else
                inline_t = TRUE;
#endif
            }
            /* completed successfully */
            break;
            
        case RC_USER_ERROR:
        case RC_NORECOVER_USER_ERROR:
        case RC_SYSTEM_ERROR:
        case RC_GCC_ERROR:
#ifdef KEY
        case RC_RTL_MISSING_ERROR: /* bug 14054 */
#endif
            user_err = TRUE;
            break;

        case RC_OVERFLOW_ERROR:
            if (!ran_twice && phase == P_be) {
                /* try recompiling with larger limits */
                ran_twice = TRUE;
                add_string(args, "-TENV:long_eh_offsets");
                add_string(args, "-TENV:large_stack");
                run_phase(phase, name, args);
                return;
            }
            internal_err = TRUE;
            break;
#ifdef KEY
        case RC_GCC_INTERNAL_ERROR:
#endif
        case RC_INTERNAL_ERROR:
            internal_err = TRUE;
            break;

        default:
            internal_err = TRUE;
            break;
        } 

        if (internal_err) {
            if (phase == P_ld ||
                phase == P_ldplus ||
#ifdef KEY
                phase == P_gas ||           // bug 4846
                phase == P_f_coco ||        // bug 9058
#ifdef PATH64_ENABLE_PSCLANG
                phase == P_psclang_cpp ||
                phase == P_psclang ||
#endif // PATH64_ENABLE_PSCLANG
                status == RC_GCC_INTERNAL_ERROR ||  //bug 9637
#endif // KEY
#ifdef PATH64_ENABLE_GNU_FRONTEND
                phase == P_spin_cc1 ||
                phase == P_spin_cc1plus ||
                phase == P_gcpp ||
                phase == P_gcpp_plus ||
#endif // PATH64_ENABLE_GNU_FRONTEND
                TRUE) {

                if (phase == P_gas ||
                    status == RC_GCC_INTERNAL_ERROR) {
                	internal_error_occurred = 1;
                }
                log_error("%s returned non-zero status %d", name, status);
                nomsg_error(status);
            } else {
                internal_error("%s returned non-zero status %d", name, status);
            }
        }
        else if (user_err) {
            /* assume phase will print diagnostics */
            if (phase == P_c_gfe || phase == P_cplus_gfe
#ifdef PATH64_ENABLE_GNU_FRONTEND
#ifdef KEY
                || phase == P_wgen
                || phase == P_spin_cc1
                || phase == P_spin_cc1plus
#endif // KEY
#endif // PATH64_ENABLE_GNU_FRONTEND
               ) {
                nomsg_error(RC_INTERNAL_ERROR);
            }
            else if (!show_flag || save_stderr) {
                nomsg_error(RC_USER_ERROR);
            } else {
                error("%s returned non-zero status %d", name, status);
            }
        }
        ran_twice = FALSE;
        return;

    } else if(WIFSIGNALED(waitstatus)) {
        termsig = WTERMSIG(waitstatus);
        switch (termsig) {
#ifdef SIGHUP
        case SIGHUP:
#endif
        case SIGINT:
#ifdef SIGQUIT
        case SIGQUIT:
#endif
#ifdef SIGKILL
        case SIGKILL:
#endif
        case SIGTERM:
            error("%s died due to signal %d", name, termsig);
            break;
        default:
            internal_error("%s died due to signal %d", name, termsig);
            break;
        }

        if(waitstatus & WCOREFLAG) {
            error("core dumped");
        }

#ifdef SIGKILL
        if (termsig == SIGKILL) {
            error("Probably caused by running out of swap space -- check %s", LOGFILE);
        }
#endif

        cleanup();
        do_exit(RC_SYSTEM_ERROR);
    } else {
        /* cannot happen, I think! */
        internal_error("driver exec'ing is confused");
        return;
    }
}
コード例 #7
0
void obtain_license (char *exedir, int argc, char *argv[]) {
    int pipes[2] ;
    int pid ;
    char exename[MAXPATHLEN] ;
    char language[10] ;
    struct stat st ;
    int i ;
    char *l ;
    char *prodname;

    const char *errortext = "Unable to obtain subscription.  The PathScale compiler cannot run without a subscription.\nPlease see http://www.pathscale.com/subscription/1.1/msgs.html for details.\n" ;
   
#ifdef TARG_MIPS
    if (!strcmp(target_cpu, "mips5kf") ||
	!strcmp(target_cpu, "twc9a")) {
      return;
    } else {
      warning("Unexpected target_cpu \"%s\" requires subscription.",
	      target_cpu ? target_cpu : "(NULL)");
    }
#endif
#ifdef NO_LICENSE_CHECK 
    return;
#endif

    l = getenv ("PATHSCALE_SUBSCRIPTION_CLIENT") ;
    if (l == NULL) {
        snprintf (exename, sizeof(exename), "%s/subclient", exedir) ;
        if (subverbose) {
            fprintf (stderr, "Subscription client: looking for %s\n", exename) ;
        }
        if (stat (exename, &st) != 0) {
            snprintf (exename, sizeof(exename), "%s/subclient",
		      get_phase_dir(P_be)) ;
            if (subverbose) {
                fprintf (stderr, "Subscription client: looking for %s\n", exename) ;
            }
            if (stat (exename, &st) != 0) {
                fprintf (stderr, "%s", errortext) ;
                do_exit (1); 
            }
        }
    } else {
        strcpy (exename, l) ;
        if (subverbose) {
            fprintf (stderr, "Subscription client: looking for %s\n", exename) ;
        }
        if (stat (exename, &st) != 0) {
            fprintf (stderr, "%s", errortext) ;
            do_exit (1); 
        }
    }

    subflags[0] = '\0' ;
    for (i = 1 ; i < argc ; i++) {
        if (argv[i][0] == '-') {
            switch (argv[i][1]) {
            case 'o':		// don't pass these as they might contain sensitive stuff
            case 'I':
            case 'L':
            case 'D':
            case 'U':
                break ;
            case 'W':
                if (strncmp (argv[i], "-Wl", 3) == 0) {
                }
                goto addflag ;
            case 'T':
                if (strncmp (argv[i], "-TENV:ipa_ident", 15) == 0) {
                    break ;
                }
                // fall through
            default:
            addflag:
                strcat (subflags, argv[i]) ;
                strcat (subflags, " ") ;
                break ;
            }
        }
    }

    switch (invoked_lang) {
    case L_f77:
        strcpy (language, "FORTRAN77") ;
	break;
    case L_f90:
        strcpy (language, "FORTRAN90") ;
	break;
    case L_cc:
        strcpy (language, "C") ;
	break;
    case L_CC:
        strcpy (language, "CC") ;
	break;
    }

    {
      // bug 12667
      char *dir = get_executable_dir();
      prodname = "Compiler";
      if (dir != NULL) {
	char *basedir = directory_path(dir);
	char *ndir = concat_strings(basedir, "/lib/" PSC_FULL_VERSION "/cray");
	if (file_exists(ndir)) {
	  prodname = "Compiler_XTS";
	}
      }
    }

    pid = fork() ;
    if (pid == 0) {		// child
        const char *argvec[8] ;

        argvec[0] = exename ;
        argvec[1] = prodname;		// bug 12667
        argvec[2] = language ;
        argvec[3] = PSC_BUILD_DATE ;
        argvec[4] = subflags ;
        argvec[5] = PSC_FULL_VERSION ;
        argvec[6] = NULL ;
        if (subverbose) {
            argvec[6] = "--v" ;
            argvec[7] = NULL ;
        }
        execv (exename, (char*const*)argvec) ;
        fprintf (stderr, "%s", errortext) ;
        do_exit (6) ;
    } else {
        int statloc ;
        waitpid (pid, &statloc, 0) ;

        // if we were not able to get a license due to missing subclient executable, tell caller
        if (WIFEXITED(statloc)) {
            if (WEXITSTATUS (statloc) == 6) {		// no subclient program?
                do_exit (1) ;
            } else if (WEXITSTATUS (statloc) == 7) {	// hard stop?
                fprintf (stderr, "Compilation terminated\n") ;
                do_exit (1) ;
            } else if (WEXITSTATUS (statloc) != 0) {            // license client failed, can't rely on output
                fprintf (stderr, "Subscription client exited with error status\n") ;
                do_exit (1) ;
            }
        } else {
	  fprintf (stderr, "Subscription client error\n") ;	// bug 9164
	  do_exit(1);
        }

    }
}
コード例 #8
0
void
add_special_options (void)
{
	int flag;
	buffer_t buf;
	char *s;
	boolean undefined_olevel_flag = FALSE; 

	/* Hack for F90 -MDupdate. We need to pass the MDupdate to mfef95, because we don't
	 * have an integrated pre-processor. I can't figure out a better way to do this, given
	 * the architecture of the phase generator. 
	 * R. Shapiro, 2/26/97
	 */
	add_phase_for_option(O_MDupdate,P_f90_fe);
	add_phase_for_option(O_MDtarget,P_f90_fe);

        add_phase_for_option(O_D, P_cppf90_fe);
        add_phase_for_option(O_U, P_cppf90_fe);
        add_phase_for_option(O_E, P_cppf90_fe);
        add_phase_for_option(O_P, P_cppf90_fe);

	if (use_ftpp == TRUE) {
		/* ftpp means pass defines directly to mfef95,
		 * and since not using gcc we have to pass some options
		 * that are otherwise implicit. */
		flag = add_string_option(O_D, "_LITTLE_ENDIAN");
		prepend_option_seen (flag);
    		flag = add_string_option(O_D, "__LONG_MAX__=9223372036854775807L");
		prepend_option_seen (flag);
		prepend_option_seen (O_cpp_nonansi);
		if (keep_flag) {
			add_phase_for_option (O_keep, P_cppf90_fe);
		}
	}

	if (option_was_seen(O_traditional)
		&& !option_was_seen(O_traditional_cpp)) 
	{
		/* pass -traditional to both gfe and cpp */
		add_phase_for_option(O_traditional, P_c_gfe);
		add_phase_for_option(O_traditional, P_cplus_gfe);
#ifdef PATH64_ENABLE_GNU_FRONTEND
#ifdef KEY
		add_phase_for_option(O_traditional, P_spin_cc1);
		add_phase_for_option(O_traditional, P_spin_cc1plus);
#endif // KEY
#endif // PATH64_ENABLE_GNU_FRONTEND
	}

#if defined(TARG_IA32)
    if(is_target_arch_MIPS()) {
        flag = add_string_option(O_D, "__NO_MATH_INLINES");
        prepend_option_seen (flag);
    }
#endif

#ifdef KEY
	// Pass -fopenmp instead of -mp to GNU 4.2 or later C/C++ front-end.
	// Bug 12824.
	if (mpkind == NORMAL_MP &&
	    (invoked_lang == L_cc ||
	     invoked_lang == L_CC)) {
	  set_option_unseen(O_mp);
	  set_option_unseen(O_openmp);
	  add_option_seen(O_fopenmp);
	}
#endif

#ifndef KEY	// Bug 4406.
	if (mpkind == CRAY_MP) {
		Process_Cray_Mp();
	}
	else if (mpkind == NORMAL_MP || auto_parallelize) {
		Process_Mp();
	}
#endif

#ifndef KEY	// Bug 7263.
        if (auto_parallelize && ipa) {
                flag = add_new_option("-IPA:array_summary");
                add_phase_for_option(flag, P_ipl);
                prepend_option_seen (flag);
        }
#endif

	if ((mpkind == NORMAL_MP 
#ifndef KEY // bug 8107
	     || auto_parallelize
#endif
	    ) && !Disable_open_mp) {
#ifdef KEY /* bug 14510 */
		flag = add_string_option(O_D, "_OPENMP=200505");
#else
		flag = add_string_option(O_D, "_OPENMP=199810");
#endif
		prepend_option_seen (flag);
	}

	if (olevel == UNDEFINED) {
		olevel = default_olevel;
		if (olevel == UNDEFINED) {
			/* if no default, use -O0 */
			olevel = 0;
		}
		flag = get_olevel_flag(olevel);
		prepend_option_seen (flag);
		// fix for bug 447
		undefined_olevel_flag = TRUE;
	}
	if (!nostdinc) {
		/* mips only: add -I path for CC */
                if (abi != ABI_I64 && abi != ABI_I32 && abi != ABI_IA32) {
                  flag = add_string_option(O_I__, 
                              concat_strings(get_phase_dir(P_include),"/CC"));
                  set_language_for_option (flag, L_CC);
                  add_option_seen (flag);
                }
	}
	if (!is_toggled(gnum)) {
		/* set gnum default */
		if (abi == ABI_RAG32) {
			/* be compatible with ucode */
			if (shared == NON_SHARED) {
				toggle(&gnum,8);
			} else {
				toggle(&gnum,0);
			}
		} else {
			toggle(&gnum,8);
		}
		sprintf(buf, "%d", gnum);
		flag = add_string_option(O_G__, buf);
		prepend_option_seen(flag);
	}

	/* Set default optimization to -O0 when compiling with -g.
	 * We leave ipa alone because mixing -ipa with -g is illegal
	 * and generates a separate error later on.
	 * NOTE: The above sentence is not correct any more, as we now
	 * allow "-g -ipa" for SiCortex 5069. This flag set still turns
	 * down opt level to -O0 if not set explicitly.
	 */
	if (undefined_olevel_flag == TRUE && glevel > 1) {
		turn_down_opt_level(0, "-g changes optimization to -O0 since no optimization level is specified");
	}

#ifdef KEY
	/* Turn off inlining when compiling -O0.  We definitly want
	 * this off when compiling with -g -O0, but we don't want
	 * -g to change the generated code so we leave it off always.
	 * See bugs 1917 and 7595.
	 */
	/* Instead of skipping inline at -O0 we now run it with -INLINE:none
	 * so it will remove unused static inline declarations.
	 */
	/* if (olevel == 0 && inline_t == UNDEFINED) */
	  /* inline_t = FALSE; */
#endif

#ifdef KEY /* Bug 5367 */
        /* In the SGI world, -g3 says to emit crippled debug info for use
	 * with optimized code. In the GNU/Pathscale world, -g3 says to emit
	 * additional debug info for C preprocessor macros, so changing -g to
	 * -g3 just because the optimization level is high makes no sense. In
	 * addition, when the language is Fortran, putting predefined C
	 * preprocessor macros into the preprocessor output causes trouble.
	 */
	if (invoked_lang == L_f90 && option_was_seen(O_g3)) {
	  glevel = 2;
	  replace_option_seen (O_g3, O_g2);
	}
#else
	if (olevel >= 2 && glevel == 2) {
		glevel = 3;
		if (option_was_seen (O_g))
			replace_option_seen (O_g, O_g3);
		if (option_was_seen (O_g2))
			replace_option_seen (O_g2, O_g3);
	}
#endif /* KEY Bug 5367 */

	if (option_was_seen(O_S) && ipa == TRUE) {
		turn_off_ipa ("-IPA -S combination not allowed, replaced with -S");
	}
	if (option_was_seen(O_S) && tirex == TRUE) {
	  turn_off_tirex ("-X -S combination not allowed, replaced with -S");
	}
#ifdef IPA_PROFILING_O3_NOT_COEXIST
	if (instrumentation_invoked == TRUE) {
	    if (ipa == TRUE) {
		inline_t = FALSE;
		turn_off_ipa ("-fb_create requires no -IPA");
	    }
	    if (olevel > 2)
		turn_down_opt_level (2, "-fb_create conflicts with -Ofast/-O3; changing to -O2");
	}
#endif
	if (Gen_feedback && olevel > 0) {
		turn_down_opt_level(0, "-fbgen conflicts with -O; changing to -O0");
	}
	if (Gen_feedback && ipa == TRUE) {
		turn_off_ipa ("-IPA -fbgen combination not allowed, replaced with -fbgen");
	}
#if 0
	/* Disable for SiCortex 5069. */
	/* Fix for BUG 451 */
	if (glevel > 1 && ipa == TRUE) {
		turn_off_ipa ("-IPA -g combination not allowed, replaced with -g");
	}
#endif
	if (ipa == TRUE) {
#ifdef KEY // bug 8130
            if (option_was_seen (O_fprofile_arcs))
	      error ("IPA not supported with -fprofile-arcs");
	    if (option_was_seen (O_ftest_coverage))
	      error ("IPA not supported with -ftest-coverage");
#endif
#ifdef FAT_WHIRL_OBJECTS
	    /* Merge phase options for be and ipl. */
	    if (olevel <= 1 || source_kind == S_O)
		flag = add_string_option(O_PHASE_, "c:i");
	    else if (olevel == 2 || source_kind == S_N)
		flag = add_string_option(O_PHASE_, "w:c:p:i");
	    else 
		flag = add_string_option(O_PHASE_, "l:w:c:p:i");
#else
	    if (olevel <= 1)
		flag = add_string_option (O_PHASE_, "i");
	    else
		flag = add_string_option (O_PHASE_, "p:i");
#endif //FAT_WHIRL_OBJECTS
	} else {
	    /*
	     * Determine which back end phase(s) need to be run.
	     *
	     *			-O0/-O1	-O2		-O3
	     *			===========================
	     *		.B,.I:	cg	wopt/cg		lno/wopt/cg
	     *		.N:	cg	wopt/cg		wopt/cg
	     *		.O:	cg	cg		cg
	     */
	    if (source_kind == S_O)
		warning("compiles of WOPT-generated .O files will usually fail due to missing state information");
	    if (olevel <= 1 || source_kind == S_O)
		flag = add_string_option(O_PHASE_, "c");
	    else if (olevel == 2 || source_kind == S_N)
		flag = add_string_option(O_PHASE_, "w:c");
	    else 
		flag = add_string_option(O_PHASE_, "l:w:c");
	}
	prepend_option_seen (flag);

	if (abi == ABI_N32 || abi == ABI_64) {
#ifndef KEY
        	set_dsm_options ();
#endif
	}

	if (option_was_seen(O_ar) && outfile == NULL) {
	   error("-ar option requires archive name to be specified with -o option");
	}
	
	if (! keep_flag && last_phase != P_be) {
		/* if going thru asm and not keeping .s file,
		 * then don't print extra notes and source */
		flag = add_string_option(O_LIST_, "source=off:notes=off");
		prepend_option_seen (flag);
	}
#ifdef TARG_X8664
        /*make the -VHO:rotate default */
	if(is_target_arch_X8664()) {
	    if(olevel >= 2) {
	        flag = add_string_option(O_VHO_, "rotate");
                prepend_option_seen (flag);   
	    }
	}
#endif // TARG_X8664
}