开发者

How do I compile this LLVM ASM?

开发者 https://www.devze.com 2023-02-03 00:50 出处:网络
I\'m just trying to play around with LLVM to figure out how it works.I\'m trying to compile the following snippet:

I'm just trying to play around with LLVM to figure out how it works. I'm trying to compile the following snippet:

;hello.ll
@.LC0 = internal constant [4 x i8] c"%d\0A\00"

declare i32 @printf(i8*, i32)

define i32 @main() {
       %cast210 = getelementptr [4 x i8]* @.LC0, i64 0, i64 0
       %result = add i32 1, 4
       call i32 @printf(i8* %cast210, i32 %result)
       ret i32 0
}

If I try to compile it with llvmc, I get the following:

% llvmc hello.ll
ld: in /tmp/llvm_1291dX/hello.o, ObjectFileAddressSpace::mappedAddress(0x54) not in any section
collect2: ld returned 1 exit status

If I compile it to bitcode and run llc and gcc on it, I get the same thing:

开发者_如何学Go% llc hello.ll
% gcc -v hello.s
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5664~89/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5664)
 /usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1 -E -lang-asm -quiet -v -imultilib x86_64 -D__DYNAMIC__ hello.s -fPIC -mmacosx-version-min=10.6.5 -m64 -mtune=core2 -o /var/folders/8g/8gcssc6aGyiiyOSGXHrLaU+++TI/-Tmp-//cc1qcw7g.s
ignoring nonexistent directory "/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../../i686-apple-darwin10/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i686-apple-darwin10/4.2.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 /usr/libexec/gcc/i686-apple-darwin10/4.2.1/as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/8g/8gcssc6aGyiiyOSGXHrLaU+++TI/-Tmp-//ccPlgnju.o /var/folders/8g/8gcssc6aGyiiyOSGXHrLaU+++TI/-Tmp-//cc1qcw7g.s
 /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch x86_64 -macosx_version_min 10.6.5 -weak_reference_mismatches non-weak -o a.out -lcrt1.10.6.o -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64 -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/folders/8g/8gcssc6aGyiiyOSGXHrLaU+++TI/-Tmp-//ccPlgnju.o -lSystem -lgcc -lSystem
ld: in /var/folders/8g/8gcssc6aGyiiyOSGXHrLaU+++TI/-Tmp-//ccPlgnju.o, ObjectFileAddressSpace::mappedAddress(0x54) not in any section
collect2: ld returned 1 exit status

However, if I JIT it with lli, it works:

% lli hello.bc
5

What am I doing wrong?


It turns out that I'm running 32-bit LLVM and 64-bit gcc. If I run gcc like this it works:

gcc -m32 hello.s -o hello
0

精彩评论

暂无评论...
验证码 换一张
取 消