I used the llvm online compiler to compile my C example code,
int main() { return 0; }
generated LLVM assembly,
; ModuleID = '/tmp/webcompile/_31588_0.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @main() nounwind uwtable {
%1 = alloca i32, align 4
store i32 0, i32* %1
ret i32 0
}
then I compiled the LLVM assembly into an obj file,
llc -filetype=obj a.ll
when I tried to link the obj file with link.exe a.o, I got an error
fatal error LNK1107: invalid or corrupt file: cannot read at 0x438
How can I generate the correct obj file for submission to link.exe?
Additional Information
- I built LLVM using Visual Studio 11. I did not have cygwin installed.
- link.exe also from Visual Studio 11
- LLVM was created from the latest source code.
If I compile the same code using the VC ++ compiler into an assembly, it looks like this:
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50402.0
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC main
; Function compile flags: /Odtp
_TEXT SEGMENT
main PROC
; File c:\tmp\u.c
; Line 1
xor eax, eax
ret 0
main ENDP
_TEXT ENDS
END
llc -filetype=asm j.llgenerates the following code. It also does not work with ml.exe.
.def _main;
.scl 2;
.type 32;
.endef
.text
.globl _main
.align 16, 0x90
_main: # @main
# BB#0:
pushl %eax
movl $0, (%esp)
xorl %eax, %eax
popl %edx
ret
source
share