【问题标题】:using clang v3.4 to compile a c/c++ source file for arm on ubuntu_x86-64使用 clang v3.4 在 ubuntu_x86-64 上为 arm 编译 c/c++ 源文件
【发布时间】:2016-03-02 11:09:59
【问题描述】:

平台:

ubuntu14.04_x86-64

clang v3.4

问题

由于我可以使用命令clang -target i386 hello.c 来编译hello.c,所以我尝试使用

clang -target arm hello.c,

clang -target armv7 hello.c,

clang -target armv7-a hello.c,

clang -target arm-eabi hello.c

为 ARM 编译 hello.c 但都失败了。

是否有关于 clang 支持的目标类型的任何信息?

$ clang -target arm-none-eabi hello.c
/tmp/hello-c8aebe.s: Assembler messages:
/tmp/hello-c8aebe.s:1: Error: unknown pseudo-op: `.syntax'
/tmp/hello-c8aebe.s:2: Error: unknown pseudo-op: `.cpu'
/tmp/hello-c8aebe.s:3: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:4: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:5: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:6: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:7: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:8: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:9: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/hello-c8aebe.s:16: Error: invalid char '{' beginning operand 1 `{r11'
/tmp/hello-c8aebe.s:17: Error: too many memory references for `mov'
/tmp/hello-c8aebe.s:18: Error: too many memory references for `sub'
/tmp/hello-c8aebe.s:19: Error: expecting operand after ','; got nothing
/tmp/hello-c8aebe.s:20: Error: invalid char '[' beginning operand 2 `[r11'
/tmp/hello-c8aebe.s:21: Error: no such instruction: `ldr r1,.LCPI0_0'
/tmp/hello-c8aebe.s:22: Error: invalid char '[' beginning operand 2 `[sp'
/tmp/hello-c8aebe.s:23: Error: too many memory references for `mov'
/tmp/hello-c8aebe.s:24: Error: no such instruction: `bl printf'
/tmp/hello-c8aebe.s:25: Error: no such instruction: `ldr r1,[sp,'
/tmp/hello-c8aebe.s:26: Error: invalid char '[' beginning operand 2 `[sp'
/tmp/hello-c8aebe.s:27: Error: too many memory references for `mov'
/tmp/hello-c8aebe.s:28: Error: too many memory references for `mov'
/tmp/hello-c8aebe.s:29: Error: invalid char '{' beginning operand 1 `{r11'
/tmp/hello-c8aebe.s:30: Error: no such instruction: `bx lr'
clang: error: assembler (via gcc) command failed with exit code 1 (use -v to see invocation)

我已经安装了gcc-linaro-arm-linux-gnueabihf-4.7,使用如下方式编译,但是指令不匹配。

clang -emit-llvm -c hello.c -o hello.bc
llc -march=arm hello.bc -o hello.s
arm-linux-gnueabihf-gcc -o hello hello.s

最后一条命令失败

【问题讨论】:

    标签: c++ c arm clang


    【解决方案1】:

    这不是“编译器支持什么目标”的问题,而是您需要与编译器一起使用的工具。这有点像在您的工具店抱怨您的套筒组能够获得您的汽车车轮,但它没有附带“从轮辋工具上取下轮胎”。

    Clang 可以为许多不同的处理器生成代码。但它将依赖外部工具从汇编中生成二进制代码[尽管我认为至少有时,它会通过内部汇编器做到这一点]并链接二进制目标文件[总是,无论如何]。

    您的目标架构需要binutils - 至少支持arm-none-eabiasld。除非您的代码也完全独立,否则您将需要为该目标构建的 C 库和 C++ 库。

    【讨论】:

    • 谢谢,我尝试了一种新的编译方式,但也没有成功。我想知道如何生成正确的 asm 指令。 'clang -emit-llvm -c hello.c -o hello.bc llc -march=arm hello.bc -o hello.s arm-linux-gnueabihf-gcc -o hello hello.s 在最后一个命令中失败:$ arm -linux-gnueabihf-gcc -o hello hello.s /usr/local/gcc-linaro-arm/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../.. /../arm-linux-gnueabihf/bin/ld: 错误: hello 使用 VFP 寄存器参数,/tmp/cc65HjLb.o 没有`
    • 所以您正在混合调用约定 - VFP 寄存器与无 VFP 寄存器。我很确定你需要-mtriple=...,但是应该在... 中输入什么,我不确定——也许是arm-linux-gnueabihf?我希望在 gcc 命令上使用-v 会有所帮助。
    • 我使用 arm-linux-gnueabihf-gcc -v 找到这个“--target=arm-linux-gnueabihf”,所以我尝试使用llc -march=arm -mtriple=arm-linux-gnueabihf hello.bc -o hello.s,但我得到了同样的错误VFP 寄存器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多