Mercurial > projects > ldc
annotate gen/linker.cpp @ 468:45a67b6f1310
Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
in this regard. Code for accessing nested variables and contexts rewritten. Probably more. Fairly well tested.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 04 Aug 2008 02:59:34 +0200 |
parents | 723027dd9593 |
children | 7e2867ed70d9 |
rev | line source |
---|---|
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
1 #include "gen/llvm.h" |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
2 #include "llvm/Linker.h" |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
3 #include "llvm/System/Program.h" |
306
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
4 #if _WIN32 |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
5 #include "llvm/Support/SystemUtils.h" |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
6 #endif |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
7 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
8 #include "root.h" |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
9 #include "mars.h" |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
10 #include "module.h" |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
11 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
12 #define NO_COUT_LOGGER |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
13 #include "gen/logger.h" |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
14 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
15 ////////////////////////////////////////////////////////////////////////////// |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
16 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
17 typedef std::vector<llvm::Module*> Module_vector; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
18 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
19 void linkModules(llvm::Module* dst, const Module_vector& MV) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
20 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
21 if (MV.empty()) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
22 return; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
23 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
24 llvm::Linker linker("llvmdc", dst); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
25 |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
26 std::string err; |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
27 for (Module_vector::const_iterator i=MV.begin(); i!=MV.end(); ++i) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
28 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
29 if (!linker.LinkInModule(*i, &err)) |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
30 { |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
31 error("%s", err.c_str()); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
32 fatal(); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
33 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
34 } |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff
changeset
|
35 } |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
36 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
37 ////////////////////////////////////////////////////////////////////////////// |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
38 |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
39 static llvm::sys::Path gExePath; |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
40 |
306
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
41 int linkExecutable(const char* argv0) |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
42 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
43 Logger::println("*** Linking executable ***"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
44 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
45 // error string |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
46 std::string errstr; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
47 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
48 // find the llvm-ld program |
306
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
49 llvm::sys::Path ldpath = llvm::sys::Program::FindProgramByName("llvm-ld"); |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
50 if (ldpath.isEmpty()) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
51 { |
306
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
52 ldpath.set("llvm-ld"); |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
53 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
54 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
55 // build arguments |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
56 std::vector<const char*> args; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
57 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
58 // first the program name ?? |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
59 args.push_back("llvm-ld"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
60 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
61 // output filename |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
62 std::string exestr; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
63 if (global.params.exefile) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
64 { // explicit |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
65 exestr = global.params.exefile; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
66 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
67 else |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
68 { // inferred |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
69 // try root module name |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
70 if (Module::rootModule) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
71 exestr = Module::rootModule->toChars(); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
72 else |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
73 exestr = "a.out"; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
74 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
75 if (global.params.isWindows) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
76 exestr.append(".exe"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
77 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
78 std::string outopt = "-o=" + exestr; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
79 args.push_back(outopt.c_str()); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
80 |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
81 // set the global gExePath |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
82 gExePath.set(exestr); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
83 assert(gExePath.isValid()); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
84 |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
85 // create path to exe |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
86 llvm::sys::Path exedir(gExePath); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
87 exedir.set(gExePath.getDirname()); |
306
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
88 if (!exedir.exists()) |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
89 { |
306
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
90 exedir.createDirectoryOnDisk(true, &errstr); |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
91 if (!errstr.empty()) |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
92 { |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
93 error("failed to create path to linking output: %s\n%s", exedir.c_str(), errstr.c_str()); |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
94 fatal(); |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
95 } |
0baca2feb554
[svn r327] Fixed some more MinGW32 issues. It's now very close to working.
lindquist
parents:
278
diff
changeset
|
96 } |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
97 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
98 // strip debug info |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
99 if (!global.params.symdebug) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
100 args.push_back("-strip-debug"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
101 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
102 // optimization level |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
103 if (!global.params.optimize) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
104 args.push_back("-disable-opt"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
105 else |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
106 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
107 const char* s = 0; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
108 switch(global.params.optimizeLevel) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
109 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
110 case 0: |
393
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
111 args.push_back("-disable-opt"); |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
112 args.push_back("-globaldce"); |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
113 break; |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
114 case 1: |
393
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
115 args.push_back("-disable-opt"); |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
116 args.push_back("-globaldce"); |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
117 args.push_back("-mem2reg"); |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
118 case 2: |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
119 case 3: |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
120 case 4: |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
121 case 5: |
393
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
122 // use default optimization |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
123 break; |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
124 default: |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
125 assert(0); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
126 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
127 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
128 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
129 // inlining |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
130 if (!(global.params.useInline || global.params.llvmInline)) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
131 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
132 args.push_back("-disable-inlining"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
133 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
134 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
135 // additional linker switches |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
136 for (int i = 0; i < global.params.linkswitches->dim; i++) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
137 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
138 char *p = (char *)global.params.linkswitches->data[i]; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
139 args.push_back(p); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
140 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
141 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
142 // native please |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
143 args.push_back("-native"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
144 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
145 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
146 // user libs |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
147 for (int i = 0; i < global.params.libfiles->dim; i++) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
148 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
149 char *p = (char *)global.params.libfiles->data[i]; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
150 args.push_back(p); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
151 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
152 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
153 // default libs |
376
6788e98ec1cd
Do only link to libpthread, libm and libdl on Linux.
Christian Kamm <kamm incasoftware de>
parents:
325
diff
changeset
|
154 if(global.params.isLinux) |
6788e98ec1cd
Do only link to libpthread, libm and libdl on Linux.
Christian Kamm <kamm incasoftware de>
parents:
325
diff
changeset
|
155 { |
6788e98ec1cd
Do only link to libpthread, libm and libdl on Linux.
Christian Kamm <kamm incasoftware de>
parents:
325
diff
changeset
|
156 args.push_back("-lpthread"); |
6788e98ec1cd
Do only link to libpthread, libm and libdl on Linux.
Christian Kamm <kamm incasoftware de>
parents:
325
diff
changeset
|
157 args.push_back("-ldl"); |
6788e98ec1cd
Do only link to libpthread, libm and libdl on Linux.
Christian Kamm <kamm incasoftware de>
parents:
325
diff
changeset
|
158 args.push_back("-lm"); |
6788e98ec1cd
Do only link to libpthread, libm and libdl on Linux.
Christian Kamm <kamm incasoftware de>
parents:
325
diff
changeset
|
159 } |
393
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
160 else if (global.params.isWindows) |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
161 { |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
162 // FIXME: I'd assume kernel32 etc |
a3f3c2770a0d
Added bitcode filename to very verbose logging.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
376
diff
changeset
|
163 } |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
164 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
165 // object files |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
166 for (int i = 0; i < global.params.objfiles->dim; i++) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
167 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
168 char *p = (char *)global.params.objfiles->data[i]; |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
169 args.push_back(p); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
170 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
171 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
172 // runtime library |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
173 // must be linked in last to null terminate the moduleinfo appending list |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
174 std::string runtime_path(global.params.runtimePath); |
407
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
175 |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
176 // path seperator can be \ on windows, but we check for / |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
177 if (global.params.isWindows) |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
178 { |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
179 int i=0; |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
180 while ((i = runtime_path.find("\\", i)) > 0) |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
181 runtime_path.replace(i, 1, "/"); |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
182 } |
723027dd9593
Fixed path seperator issue on windows in linker.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
393
diff
changeset
|
183 |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
184 if (*runtime_path.rbegin() != '/') |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
185 runtime_path.append("/"); |
325
3c8c58c24aa8
[svn r346] Fixed #55 - llvmdc can link as fast as dmd now!
ChristianK
parents:
306
diff
changeset
|
186 runtime_path.append("libtango-base-llvmdc-native.a"); |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
187 args.push_back(runtime_path.c_str()); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
188 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
189 // print link command? |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
190 if (!global.params.quiet || global.params.verbose) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
191 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
192 // Print it |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
193 for (int i = 0; i < args.size(); i++) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
194 printf("%s ", args[i]); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
195 printf("\n"); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
196 fflush(stdout); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
197 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
198 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
199 // terminate args list |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
200 args.push_back(NULL); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
201 |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
202 // try to call linker!!! |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
203 if (int status = llvm::sys::Program::ExecuteAndWait(ldpath, &args[0], NULL, NULL, 0,0, &errstr)) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
204 { |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
205 error("linking failed:\nstatus: %d", status); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
206 if (!errstr.empty()) |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
207 error("message: %s", errstr.c_str()); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
208 fatal(); |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
209 } |
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
244
diff
changeset
|
210 } |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
211 |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
212 ////////////////////////////////////////////////////////////////////////////// |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
213 |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
214 void deleteExecutable() |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
215 { |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
216 if (!gExePath.isEmpty()) |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
217 { |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
218 assert(gExePath.isValid()); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
219 assert(!gExePath.isDirectory()); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
220 gExePath.eraseFromDisk(false); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
221 } |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
222 } |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
223 |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
224 ////////////////////////////////////////////////////////////////////////////// |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
225 |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
226 int runExectuable() |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
227 { |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
228 assert(!gExePath.isEmpty()); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
229 assert(gExePath.isValid()); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
230 |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
231 // build arguments |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
232 std::vector<const char*> args; |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
233 for (size_t i = 0; i < global.params.runargs_length; i++) |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
234 { |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
235 char *a = global.params.runargs[i]; |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
236 args.push_back(a); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
237 } |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
238 // terminate args list |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
239 args.push_back(NULL); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
240 |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
241 // try to call linker!!! |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
242 std::string errstr; |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
243 int status = llvm::sys::Program::ExecuteAndWait(gExePath, &args[0], NULL, NULL, 0,0, &errstr); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
244 if (!errstr.empty()) |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
245 { |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
246 error("failed to execute program"); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
247 if (!errstr.empty()) |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
248 error("error message: %s", errstr.c_str()); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
249 fatal(); |
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
250 } |
278
30941d8ee320
[svn r299] forgot to return status in runExecutable
lindquist
parents:
277
diff
changeset
|
251 return status; |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
252 } |