int create_tmpdir ( int tracing ) { int fixedname = ipa && ( option[OPT_KEEP_TEMPS].flag ); if ( ipa ) { if ( fixedname ) { tmpdir = concat_names ( outfilename, ".ipakeep" ); } else { char *tmpdir_env_var; if ((tmpdir_env_var = getenv("TMPDIR")) != NULL) { char *filename; tmpdir_env_var = concat_names ( tmpdir_env_var, DIR_SEP_CHAR); if ((filename = strrchr(outfilename, DIR_SEP_CHAR)) != NULL) filename++; else filename = outfilename; tmpdir = concat_names ( tmpdir_env_var, filename); } else tmpdir = outfilename; tmpdir = concat_names ( tmpdir, ".ipaXXXXXX" ); } } else { tmpdir = concat_names ( DEFAULT_TMPDIR, "XXXXXX" ); } if ( ! fixedname ) { tmpdir = mktemp ( tmpdir ); } tmpdir_length = strlen ( tmpdir ); if ( cmask == 0 ) { cmask = umask (0); (void) umask (cmask); } if ( MKDIR (tmpdir, 0777 & ~cmask) != 0 ) { if ( errno == EEXIST && fixedname ) { /* We have an old instance of this directory -- clear it out: */ DIR *dirp; struct direct *entryp; char *prefix; dirp = opendir ( tmpdir ); if ( dirp != NULL ) { prefix = concat_names ( tmpdir, "/" ); while ( ( entryp = readdir(dirp) ) != NULL ) { /* Don't bother with names of one or two characters, e.g. '.' * and '..', since we don't create temporary files with such * names: */ #if defined(_DIRENT_HAVE_D_NAMLEN) if ( entryp->d_namlen > 2 ) #else if (_D_EXACT_NAMLEN(entryp) > 2) #endif { string fname = concat_names ( prefix, entryp->d_name); unlink (fname); FREE (fname); } } FREE (prefix); closedir ( dirp ); } } else { perror(""cannot create temporary directory for code generation"); return -1; } } add_to_tmp_file_list ( tmpdir ); return 0; } /* create_tmpdir */
/******************************************************* Function: ld_compile *******************************************************/ string ld_compile (bfd *abfd) { string input_path; string output_path; int argc; string *argv; int child_pid; int statptr; string file_name = (string)abfd->filename; if (tmpdir == 0) if (create_tmpdir (FALSE) != 0) { fprintf(stderr,"create_tmpdir() failed for %s\n",abfd->filename); exit(1); } if ((input_path = create_unique_file (file_name, 'B')) == 0) { fprintf(stderr,"create_unique_file() failed for %s\n",abfd->filename); exit(1); } if (abfd->arelt_data) { if (extract_archive_member (abfd, input_path) != 0) { fprintf(stderr,"extract_archive_member() failed for %s\n",abfd->filename); exit(1); } } else { UNLINK (input_path); if (make_link (file_name, input_path) != 0) { fprintf(stderr,"make_link() failed for %s\n",abfd->filename); exit(1); } } if ((output_path = create_unique_file (file_name, 'o')) == 0) { fprintf(stderr,"create_unique_file() failed for %s\n",abfd->filename); exit(1); } add_to_tmp_file_list (output_path); add_to_tmp_file_list (input_path); argv = get_command_line (abfd, input_path, output_path, &argc); if (ld_ipa_opt[LD_IPA_VERBOSE].flag || ld_ipa_opt[LD_IPA_SHOW].flag) fprintf(stderr,"Compiling %s\n",abfd->filename); child_pid = do_compile (argv); (void) waitpid (child_pid, &statptr, 0); if (statptr != 0 && WEXITSTATUS(statptr) != 0) { fprintf(stderr,"Compile of %s failed!\n",abfd->filename); exit(1); } active_pid = 0; FREE (argv); UNLINK (input_path); remove_from_tmp_file_list (input_path); FREE (input_path); return output_path; } /* ld_compile */