John Slagel
2012-Nov-07 16:28 UTC
[LLVMdev] How to link code into EXE, or, am I doing this wrong?
Hi, I've been writing a 80's era-flavor of QuickBASIC compiler based on LLVM, and it's come surprisingly far very quickly, LLVM is working great. GOSUB's, GOTO's, FIELD statements. I'm using Visual Studio 2010. Here's my setup: I use LLVM to turn my AST into code, which, during debugging I then execute natively using "getPointerToFunction" and the runtime library it uses is a .lib in my VS2010 project that it calls into. Then, to produce an EXE, I use addPassesToEmitFile to produce an .OBJ file for the native machine (x86 windows), which I then link with my runtime library using the Visual Studio linker: link.exe test.bas.obj debug\BPRuntime.lib kernel32.lib /subsystem:console Which produces a native executable that executes just fine under Windows. All of that works great. What I can't figure out, even after LOTS of searching, is how to replace that with a LLVM linker or some other linker so that I can give out my compiler and people could use it to make EXE files. I found similar posts and questions but no good answers, and it seems that some of this (an LLVM linker) is in flux. Or, am I going about this wrong? Should I be generating bitcode and making my runtime lib be bitcode and then link them using LLVM tools? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121107/36a8e3fa/attachment.html>
Michael Spencer
2012-Nov-07 18:46 UTC
[LLVMdev] How to link code into EXE, or, am I doing this wrong?
On Wed, Nov 7, 2012 at 8:28 AM, John Slagel <john.slagel at gmail.com> wrote:> Hi, > > I've been writing a 80's era-flavor of QuickBASIC compiler based on LLVM, > and it's come surprisingly far very quickly, LLVM is working great. GOSUB's, > GOTO's, FIELD statements. > I'm using Visual Studio 2010. > Here's my setup: I use LLVM to turn my AST into code, which, during > debugging I then execute natively using "getPointerToFunction" and the > runtime library it uses is a .lib in my VS2010 project that it calls into. > Then, to produce an EXE, I use addPassesToEmitFile to produce an .OBJ file > for the native machine (x86 windows), which I then link with my runtime > library using the Visual Studio linker: > > link.exe test.bas.obj debug\BPRuntime.lib kernel32.lib /subsystem:console > > Which produces a native executable that executes just fine under Windows. > > All of that works great. > > What I can't figure out, even after LOTS of searching, is how to replace > that with a LLVM linker or some other linker so that I can give out my > compiler and people could use it to make EXE files. I found similar posts > and questions but no good answers, and it seems that some of this (an LLVM > linker) is in flux. > > Or, am I going about this wrong? Should I be generating bitcode and making > my runtime lib be bitcode and then link them using LLVM tools? > > Thanks!llvm currently has no way to generate PECOFF executables except to rely on the system linker. Your current options are: * Include the MinGW ld in your distribution. * Always use the llvm jit (with or without compiling your runtime to bitcode). * Wait for http://lld.llvm.org/ to become feature complete. - Michael Spencer
Joe Groff
2012-Nov-08 02:25 UTC
[LLVMdev] How to link code into EXE, or, am I doing this wrong?
On Wed, Nov 7, 2012 at 10:46 AM, Michael Spencer <bigcheesegs at gmail.com>wrote:> > llvm currently has no way to generate PECOFF executables except to > rely on the system linker. Your current options are: > > * Include the MinGW ld in your distribution. > * Always use the llvm jit (with or without compiling your runtime to > bitcode). > * Wait for http://lld.llvm.org/ to become feature complete. >If you build for an i386-*-win32 or x86_64-*-win32 target, you should also be able to link LLVM object files with the MSVC link.exe. -Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121107/549116d0/attachment.html>
Apparently Analagous Threads
- [LLVMdev] How to link code into EXE, or, am I doing this wrong?
- [LLVMdev] how to compile asm output for x86 with Micorsoft's ML
- [LLVMdev] [lld][PECOFF] assert from lld once in 5 test runs.
- Clang/LLVM JIT - When to use "registerEHFrames()"
- [LLVMdev] [lld] filename in the atom model.