[英]How to generate executable from LLVM IR
I was reading http://www.stephendiehl.com/llvm/#llvm-introduction there is a piece of LLVM IR like this: 我在阅读http://www.stephendiehl.com/llvm/#llvm-introduction,其中有一段LLVM IR,如下所示:
declare i32 @putchar(i32)
define i32 @add(i32 %a, i32 %b) {
%1 = add i32 %a, %b
ret i32 %1
}
define void @main() {
%1 = call i32 @add(i32 0, i32 97)
call i32 @putchar(i32 %1)
ret void
}
I wanted to try running this by using llvm
and nasm
but failed: 我想尝试使用llvm
和nasm
来运行它,但是失败了:
llc -march=x86-64 h1.bc -o h1.s
nasm -f macho -o h1.o h1.s
# failed here
first lines of the errors are: 错误的第一行是:
h1.s:1: error: attempt to define a local label before any non-local labels
h1.s:1: error: parser: instruction expected
h1.s:2: error: attempt to define a local label before any non-local labels
h1.s:2: error: parser: instruction expected
h1.s:3: error: attempt to define a local label before any non-local labels
h1.s:3: error: parser: instruction expected
h1.s:4: error: attempt to define a local label before any non-local labels
the code generated from llc
does not seem to be native OS X Assembly code described at http://peter.michaux.ca/articles/assembly-hello-world-for-os-x 从llc
生成的代码似乎不是本机的OS X汇编代码,请参见http://peter.michaux.ca/articles/assembly-hello-world-for-os-x
What's the right commands to generate an executable? 生成可执行文件的正确命令是什么?
nasm does not support AT&T assembly syntax hence the error. nasm不支持AT&T汇编语法,因此会出现错误。 On OS X you need to use "as" to assemble (and forget about nasm in 99% cases except when explicitly requested) 在OS X上,您需要使用“ as”进行组装(除非明确要求,否则在99%的情况下请忽略nasm)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.