【问题标题】:How do I compile this LLVM ASM?如何编译这个 LLVM ASM?
【发布时间】:2011-01-04 18:17:58
【问题描述】:

我只是在尝试使用 LLVM 来弄清楚它是如何工作的。我正在尝试编译以下 sn-p:

;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
}

如果我尝试用llvmc 编译它,我会得到以下信息:

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

如果我将其编译为位码并在其上运行 llcgcc,我会得到同样的结果:

% 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

但是,如果我使用 lli 对其进行 JIT,它可以工作:

% lli hello.bc
5

我做错了什么?

【问题讨论】:

  • 显然,您的 gcc 构建已损坏。试试 'gcc -v' 看看发生了什么。
  • @SK-logic - 用gcc -v 的输出更新了问题。

标签: compiler-construction assembly llvm bytecode


【解决方案1】:

事实证明,我正在运行 32 位 LLVM 和 64 位 gcc。如果我像这样运行gcc,它会起作用:

gcc -m32 hello.s -o hello

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2020-01-19
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    相关资源
    最近更新 更多