Chris Lattner | a58d2be | 2003-09-30 03:24:28 +0000 | [diff] [blame] | 1 | //===- GenerateCode.cpp - Functions for generating executable files ------===// |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains functions for generating executable files once linking |
| 11 | // has finished. This includes generating a shell script to run the JIT or |
| 12 | // a native executable derived from the bytecode. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 16 | #include "gccld.h" |
Reid Spencer | 605b9e2 | 2004-11-14 23:00:08 +0000 | [diff] [blame] | 17 | #include "llvm/Linker.h" |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/PassManager.h" |
Chris Lattner | cc650b6 | 2003-11-09 19:55:09 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/LoadValueNumbering.h" |
Chris Lattner | 2d26ffb | 2004-07-27 08:13:15 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/Passes.h" |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/Verifier.h" |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 23 | #include "llvm/Bytecode/WriteBytecodePass.h" |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetData.h" |
| 25 | #include "llvm/Transforms/IPO.h" |
| 26 | #include "llvm/Transforms/Scalar.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 27 | #include "llvm/Support/SystemUtils.h" |
| 28 | #include "llvm/Support/CommandLine.h" |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Chris Lattner | 246ce3c | 2003-10-24 18:09:23 +0000 | [diff] [blame] | 31 | namespace { |
| 32 | cl::opt<bool> |
| 33 | DisableInline("disable-inlining", cl::desc("Do not run the inliner pass")); |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 34 | |
| 35 | cl::opt<bool> |
| 36 | Verify("verify", cl::desc("Verify intermediate results of all passes")); |
| 37 | |
| 38 | cl::opt<bool> |
| 39 | DisableOptimizations("disable-opt", |
| 40 | cl::desc("Do not run any optimization passes")); |
Chris Lattner | 246ce3c | 2003-10-24 18:09:23 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Chris Lattner | 0ebee74 | 2004-06-02 00:22:24 +0000 | [diff] [blame] | 43 | /// CopyEnv - This function takes an array of environment variables and makes a |
| 44 | /// copy of it. This copy can then be manipulated any way the caller likes |
| 45 | /// without affecting the process's real environment. |
| 46 | /// |
| 47 | /// Inputs: |
| 48 | /// envp - An array of C strings containing an environment. |
| 49 | /// |
| 50 | /// Return value: |
| 51 | /// NULL - An error occurred. |
| 52 | /// |
| 53 | /// Otherwise, a pointer to a new array of C strings is returned. Every string |
| 54 | /// in the array is a duplicate of the one in the original array (i.e. we do |
| 55 | /// not copy the char *'s from one array to another). |
| 56 | /// |
| 57 | static char ** CopyEnv(char ** const envp) { |
| 58 | // Count the number of entries in the old list; |
| 59 | unsigned entries; // The number of entries in the old environment list |
| 60 | for (entries = 0; envp[entries] != NULL; entries++) |
| 61 | /*empty*/; |
| 62 | |
| 63 | // Add one more entry for the NULL pointer that ends the list. |
| 64 | ++entries; |
| 65 | |
| 66 | // If there are no entries at all, just return NULL. |
| 67 | if (entries == 0) |
| 68 | return NULL; |
| 69 | |
| 70 | // Allocate a new environment list. |
| 71 | char **newenv = new char* [entries]; |
| 72 | if ((newenv = new char* [entries]) == NULL) |
| 73 | return NULL; |
| 74 | |
| 75 | // Make a copy of the list. Don't forget the NULL that ends the list. |
| 76 | entries = 0; |
| 77 | while (envp[entries] != NULL) { |
| 78 | newenv[entries] = new char[strlen (envp[entries]) + 1]; |
| 79 | strcpy (newenv[entries], envp[entries]); |
| 80 | ++entries; |
| 81 | } |
| 82 | newenv[entries] = NULL; |
| 83 | |
| 84 | return newenv; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | /// RemoveEnv - Remove the specified environment variable from the environment |
| 89 | /// array. |
| 90 | /// |
| 91 | /// Inputs: |
| 92 | /// name - The name of the variable to remove. It cannot be NULL. |
| 93 | /// envp - The array of environment variables. It cannot be NULL. |
| 94 | /// |
| 95 | /// Notes: |
| 96 | /// This is mainly done because functions to remove items from the environment |
| 97 | /// are not available across all platforms. In particular, Solaris does not |
| 98 | /// seem to have an unsetenv() function or a setenv() function (or they are |
| 99 | /// undocumented if they do exist). |
| 100 | /// |
| 101 | static void RemoveEnv(const char * name, char ** const envp) { |
| 102 | for (unsigned index=0; envp[index] != NULL; index++) { |
| 103 | // Find the first equals sign in the array and make it an EOS character. |
| 104 | char *p = strchr (envp[index], '='); |
| 105 | if (p == NULL) |
| 106 | continue; |
| 107 | else |
| 108 | *p = '\0'; |
| 109 | |
| 110 | // Compare the two strings. If they are equal, zap this string. |
| 111 | // Otherwise, restore it. |
| 112 | if (!strcmp(name, envp[index])) |
| 113 | *envp[index] = '\0'; |
| 114 | else |
| 115 | *p = '='; |
| 116 | } |
| 117 | |
| 118 | return; |
| 119 | } |
| 120 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 121 | static inline void addPass(PassManager &PM, Pass *P) { |
| 122 | // Add the pass to the pass manager... |
| 123 | PM.add(P); |
| 124 | |
| 125 | // If we are verifying all of the intermediate steps, add the verifier... |
| 126 | if (Verify) PM.add(createVerifierPass()); |
| 127 | } |
| 128 | |
Misha Brukman | 1c53405 | 2003-09-30 17:42:57 +0000 | [diff] [blame] | 129 | /// GenerateBytecode - generates a bytecode file from the specified module. |
| 130 | /// |
| 131 | /// Inputs: |
| 132 | /// M - The module for which bytecode should be generated. |
| 133 | /// Strip - Flags whether symbols should be stripped from the output. |
| 134 | /// Internalize - Flags whether all symbols should be marked internal. |
| 135 | /// Out - Pointer to file stream to which to write the output. |
| 136 | /// |
Misha Brukman | 1c53405 | 2003-09-30 17:42:57 +0000 | [diff] [blame] | 137 | /// Returns non-zero value on error. |
| 138 | /// |
Chris Lattner | 27a9b27 | 2004-04-06 16:54:04 +0000 | [diff] [blame] | 139 | int llvm::GenerateBytecode(Module *M, bool Strip, bool Internalize, |
| 140 | std::ostream *Out) { |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 141 | // In addition to just linking the input from GCC, we also want to spiff it up |
| 142 | // a little bit. Do this now. |
| 143 | PassManager Passes; |
| 144 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 145 | if (Verify) Passes.add(createVerifierPass()); |
| 146 | |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 147 | // Add an appropriate TargetData instance for this module... |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 148 | addPass(Passes, new TargetData("gccld", M)); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 149 | |
Chris Lattner | 548e813 | 2003-11-28 09:44:03 +0000 | [diff] [blame] | 150 | // Often if the programmer does not specify proper prototypes for the |
| 151 | // functions they are calling, they end up calling a vararg version of the |
| 152 | // function that does not get a body filled in (the real function has typed |
| 153 | // arguments). This pass merges the two functions. |
| 154 | addPass(Passes, createFunctionResolvingPass()); |
| 155 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 156 | if (!DisableOptimizations) { |
Chris Lattner | dd429c6 | 2004-02-25 21:35:13 +0000 | [diff] [blame] | 157 | if (Internalize) { |
| 158 | // Now that composite has been compiled, scan through the module, looking |
| 159 | // for a main function. If main is defined, mark all other functions |
| 160 | // internal. |
| 161 | addPass(Passes, createInternalizePass()); |
| 162 | } |
| 163 | |
Chris Lattner | 93a00e4 | 2004-10-07 04:12:02 +0000 | [diff] [blame] | 164 | // Now that we internalized some globals, see if we can hack on them! |
| 165 | addPass(Passes, createGlobalOptimizerPass()); |
Chris Lattner | dd429c6 | 2004-02-25 21:35:13 +0000 | [diff] [blame] | 166 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 167 | // Linking modules together can lead to duplicated global constants, only |
| 168 | // keep one copy of each constant... |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 169 | addPass(Passes, createConstantMergePass()); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 170 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 171 | // If the -s command line option was specified, strip the symbols out of the |
| 172 | // resulting program to make it smaller. -s is a GCC option that we are |
| 173 | // supporting. |
| 174 | if (Strip) |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 175 | addPass(Passes, createSymbolStrippingPass()); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 176 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 177 | // Propagate constants at call sites into the functions they call. |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 178 | addPass(Passes, createIPConstantPropagationPass()); |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 179 | |
| 180 | // Remove unused arguments from functions... |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 181 | addPass(Passes, createDeadArgEliminationPass()); |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 182 | |
| 183 | if (!DisableInline) |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 184 | addPass(Passes, createFunctionInliningPass()); // Inline small functions |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 185 | |
Chris Lattner | f9c455d | 2004-04-12 05:38:15 +0000 | [diff] [blame] | 186 | addPass(Passes, createPruneEHPass()); // Remove dead EH info |
Chris Lattner | e3ef9b5 | 2004-10-11 04:47:18 +0000 | [diff] [blame] | 187 | addPass(Passes, createGlobalOptimizerPass()); // Optimize globals again. |
Chris Lattner | f9c455d | 2004-04-12 05:38:15 +0000 | [diff] [blame] | 188 | addPass(Passes, createGlobalDCEPass()); // Remove dead functions |
| 189 | |
Chris Lattner | f8338c4 | 2004-03-07 22:12:40 +0000 | [diff] [blame] | 190 | // If we didn't decide to inline a function, check to see if we can |
| 191 | // transform it to pass arguments by value instead of by reference. |
| 192 | addPass(Passes, createArgumentPromotionPass()); |
| 193 | |
Chris Lattner | f74a401 | 2004-02-26 03:34:30 +0000 | [diff] [blame] | 194 | // The IPO passes may leave cruft around. Clean up after them. |
| 195 | addPass(Passes, createInstructionCombiningPass()); |
| 196 | |
| 197 | addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas |
| 198 | |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 199 | // Run a few AA driven optimizations here and now, to cleanup the code. |
Chris Lattner | 93127fb | 2004-08-02 10:10:08 +0000 | [diff] [blame] | 200 | addPass(Passes, createGlobalsModRefPass()); // IP alias analysis |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 201 | |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 202 | addPass(Passes, createLICMPass()); // Hoist loop invariants |
| 203 | addPass(Passes, createLoadValueNumberingPass()); // GVN for load instrs |
| 204 | addPass(Passes, createGCSEPass()); // Remove common subexprs |
Chris Lattner | 2d26ffb | 2004-07-27 08:13:15 +0000 | [diff] [blame] | 205 | addPass(Passes, createDeadStoreEliminationPass()); // Nuke dead stores |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 206 | |
Chris Lattner | f74a401 | 2004-02-26 03:34:30 +0000 | [diff] [blame] | 207 | // Cleanup and simplify the code after the scalar optimizations. |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 208 | addPass(Passes, createInstructionCombiningPass()); |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 209 | |
| 210 | // Delete basic blocks, which optimization passes may have killed... |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 211 | addPass(Passes, createCFGSimplificationPass()); |
Brian Gaeke | 1ab90d4 | 2003-11-16 23:07:28 +0000 | [diff] [blame] | 212 | |
| 213 | // Now that we have optimized the program, discard unreachable functions... |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 214 | addPass(Passes, createGlobalDCEPass()); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Chris Lattner | 0cccb18 | 2004-01-14 03:39:46 +0000 | [diff] [blame] | 217 | // Make sure everything is still good. |
| 218 | Passes.add(createVerifierPass()); |
| 219 | |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 220 | // Add the pass that writes bytecode to the output file... |
Misha Brukman | 438e364 | 2003-11-20 06:26:15 +0000 | [diff] [blame] | 221 | addPass(Passes, new WriteBytecodePass(Out)); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 222 | |
| 223 | // Run our queue of passes all at once now, efficiently. |
| 224 | Passes.run(*M); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
Misha Brukman | 1c53405 | 2003-09-30 17:42:57 +0000 | [diff] [blame] | 229 | /// GenerateAssembly - generates a native assembly language source file from the |
| 230 | /// specified bytecode file. |
| 231 | /// |
| 232 | /// Inputs: |
| 233 | /// InputFilename - The name of the output bytecode file. |
| 234 | /// OutputFilename - The name of the file to generate. |
| 235 | /// llc - The pathname to use for LLC. |
| 236 | /// envp - The environment to use when running LLC. |
| 237 | /// |
Misha Brukman | 1c53405 | 2003-09-30 17:42:57 +0000 | [diff] [blame] | 238 | /// Return non-zero value on error. |
| 239 | /// |
Chris Lattner | 27a9b27 | 2004-04-06 16:54:04 +0000 | [diff] [blame] | 240 | int llvm::GenerateAssembly(const std::string &OutputFilename, |
| 241 | const std::string &InputFilename, |
| 242 | const std::string &llc, |
| 243 | char ** const envp) { |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 244 | // Run LLC to convert the bytecode file into assembly code. |
Chris Lattner | 27a9b27 | 2004-04-06 16:54:04 +0000 | [diff] [blame] | 245 | const char *cmd[6]; |
Misha Brukman | b6b2843 | 2003-09-30 17:40:12 +0000 | [diff] [blame] | 246 | cmd[0] = llc.c_str(); |
| 247 | cmd[1] = "-f"; |
| 248 | cmd[2] = "-o"; |
| 249 | cmd[3] = OutputFilename.c_str(); |
| 250 | cmd[4] = InputFilename.c_str(); |
Chris Lattner | 27a9b27 | 2004-04-06 16:54:04 +0000 | [diff] [blame] | 251 | cmd[5] = 0; |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 252 | |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 253 | return ExecWait(cmd, envp); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Chris Lattner | 69e8d28 | 2004-04-06 16:43:13 +0000 | [diff] [blame] | 256 | /// GenerateAssembly - generates a native assembly language source file from the |
| 257 | /// specified bytecode file. |
Chris Lattner | 27a9b27 | 2004-04-06 16:54:04 +0000 | [diff] [blame] | 258 | int llvm::GenerateCFile(const std::string &OutputFile, |
| 259 | const std::string &InputFile, |
| 260 | const std::string &llc, char ** const envp) { |
Chris Lattner | 69e8d28 | 2004-04-06 16:43:13 +0000 | [diff] [blame] | 261 | // Run LLC to convert the bytecode file into C. |
Chris Lattner | 67e0a34 | 2004-04-08 15:18:03 +0000 | [diff] [blame] | 262 | const char *cmd[7]; |
Chris Lattner | 69e8d28 | 2004-04-06 16:43:13 +0000 | [diff] [blame] | 263 | |
| 264 | cmd[0] = llc.c_str(); |
| 265 | cmd[1] = "-march=c"; |
| 266 | cmd[2] = "-f"; |
Chris Lattner | 67e0a34 | 2004-04-08 15:18:03 +0000 | [diff] [blame] | 267 | cmd[3] = "-o"; |
| 268 | cmd[4] = OutputFile.c_str(); |
| 269 | cmd[5] = InputFile.c_str(); |
| 270 | cmd[6] = 0; |
Chris Lattner | 69e8d28 | 2004-04-06 16:43:13 +0000 | [diff] [blame] | 271 | return ExecWait(cmd, envp); |
| 272 | } |
| 273 | |
Misha Brukman | 1c53405 | 2003-09-30 17:42:57 +0000 | [diff] [blame] | 274 | /// GenerateNative - generates a native assembly language source file from the |
| 275 | /// specified assembly source file. |
| 276 | /// |
| 277 | /// Inputs: |
| 278 | /// InputFilename - The name of the output bytecode file. |
| 279 | /// OutputFilename - The name of the file to generate. |
| 280 | /// Libraries - The list of libraries with which to link. |
| 281 | /// LibPaths - The list of directories in which to find libraries. |
| 282 | /// gcc - The pathname to use for GGC. |
| 283 | /// envp - A copy of the process's current environment. |
| 284 | /// |
| 285 | /// Outputs: |
| 286 | /// None. |
| 287 | /// |
| 288 | /// Returns non-zero value on error. |
| 289 | /// |
Chris Lattner | 27a9b27 | 2004-04-06 16:54:04 +0000 | [diff] [blame] | 290 | int llvm::GenerateNative(const std::string &OutputFilename, |
| 291 | const std::string &InputFilename, |
| 292 | const std::vector<std::string> &Libraries, |
| 293 | const std::vector<std::string> &LibPaths, |
| 294 | const std::string &gcc, char ** const envp) { |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 295 | // Remove these environment variables from the environment of the |
| 296 | // programs that we will execute. It appears that GCC sets these |
| 297 | // environment variables so that the programs it uses can configure |
| 298 | // themselves identically. |
| 299 | // |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 300 | // However, when we invoke GCC below, we want it to use its normal |
| 301 | // configuration. Hence, we must sanitize its environment. |
| 302 | char ** clean_env = CopyEnv(envp); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 303 | if (clean_env == NULL) |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 304 | return 1; |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 305 | RemoveEnv("LIBRARY_PATH", clean_env); |
| 306 | RemoveEnv("COLLECT_GCC_OPTIONS", clean_env); |
| 307 | RemoveEnv("GCC_EXEC_PREFIX", clean_env); |
| 308 | RemoveEnv("COMPILER_PATH", clean_env); |
| 309 | RemoveEnv("COLLECT_GCC", clean_env); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 310 | |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 311 | std::vector<const char *> cmd; |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 312 | |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 313 | // Run GCC to assemble and link the program into native code. |
| 314 | // |
| 315 | // Note: |
| 316 | // We can't just assemble and link the file with the system assembler |
| 317 | // and linker because we don't know where to put the _start symbol. |
| 318 | // GCC mysteriously knows how to do it. |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 319 | cmd.push_back(gcc.c_str()); |
Chris Lattner | a1346a2 | 2004-04-08 15:18:59 +0000 | [diff] [blame] | 320 | cmd.push_back("-fno-strict-aliasing"); |
Chris Lattner | 69e8d28 | 2004-04-06 16:43:13 +0000 | [diff] [blame] | 321 | cmd.push_back("-O3"); |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 322 | cmd.push_back("-o"); |
| 323 | cmd.push_back(OutputFilename.c_str()); |
| 324 | cmd.push_back(InputFilename.c_str()); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 325 | |
Misha Brukman | b6b2843 | 2003-09-30 17:40:12 +0000 | [diff] [blame] | 326 | // Adding the library paths creates a problem for native generation. If we |
| 327 | // include the search paths from llvmgcc, then we'll be telling normal gcc |
| 328 | // to look inside of llvmgcc's library directories for libraries. This is |
| 329 | // bad because those libraries hold only bytecode files (not native object |
| 330 | // files). In the end, we attempt to link the bytecode libgcc into a native |
| 331 | // program. |
Chris Lattner | 238cf3c | 2003-09-30 17:36:51 +0000 | [diff] [blame] | 332 | #if 0 |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 333 | // Add in the library path options. |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 334 | for (unsigned index=0; index < LibPaths.size(); index++) { |
| 335 | cmd.push_back("-L"); |
| 336 | cmd.push_back(LibPaths[index].c_str()); |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 337 | } |
| 338 | #endif |
| 339 | |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 340 | // Add in the libraries to link. |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 341 | std::vector<std::string> Libs(Libraries); |
| 342 | for (unsigned index = 0; index < Libs.size(); index++) { |
John Criswell | 6f5592a | 2004-01-26 23:51:10 +0000 | [diff] [blame] | 343 | if (Libs[index] != "crtend") { |
| 344 | Libs[index] = "-l" + Libs[index]; |
| 345 | cmd.push_back(Libs[index].c_str()); |
| 346 | } |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 347 | } |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 348 | cmd.push_back(NULL); |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 349 | |
John Criswell | 71478b7 | 2003-09-19 20:24:23 +0000 | [diff] [blame] | 350 | // Run the compiler to assembly and link together the program. |
Misha Brukman | bb5a4d0 | 2003-09-30 17:33:12 +0000 | [diff] [blame] | 351 | return ExecWait(&(cmd[0]), clean_env); |
John Criswell | dc0de4f | 2003-09-18 16:22:26 +0000 | [diff] [blame] | 352 | } |
Chris Lattner | 0ebee74 | 2004-06-02 00:22:24 +0000 | [diff] [blame] | 353 | |