Ich versuche nur mit LLVM herumzuspielen, um herauszufinden, wie es funktioniert. Ich versuche, den folgenden Code-Schnipsel zu kompilieren:Wie kompiliere ich dieses LLVM ASM?
;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
}
Wenn ich versuche, es zu kompilieren mit llvmc
, erhalte ich die folgenden:
% llvmc hello.ll
ld: in /tmp/llvm_1291dX/hello.o, ObjectFileAddressSpace::mappedAddress(0x54) not in any section
collect2: ld returned 1 exit status
Wenn ich es kompilieren Bitcode und laufe llc
und gcc
auf es, ich die gleiche Sache erhalten:
% 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
Allerdings, wenn ich es mit lli
JIT, funktioniert es:
% lli hello.bc
5
Was mache ich falsch?
Offenbar Ihr gcc Build gebrochen ist. Probieren Sie 'gcc -v' aus, um zu sehen, was vor sich geht. –
@ SK-logic - Aktualisierte die Frage mit 'gcc -v's Ausgabe. –