我的英语水平很差,因为我不是以英语为母语的人。
我使用 llc.exe 编译了一个位码并获得了一个 .s 文件(test.s)。我用来创建 test.s 的命令如下。
llc -march=thumb -mattr=thumb2 -mcpu=cortex-m3 main.bc -o test.s
是的,我的目标板是 cortex-m3(stm32l 系列),我创建了如下的 makefile 来创建 .bin 文件。
bin: test.s
@echo "Running target all"
arm-none-eabi-as c:/backend/files/test.s -o c:/backend/files/test.o
arm-none-eabi-ld -Ttext=0x08000000 c:/backend/files/test.o -o c:/backend/files/test.elf
arm-none-eabi-objdump -D c:/backend/files/test.elf
arm-none-eabi-objcopy c:/backend/files/test.elf -O binary c:/backend/files/test.bin
clean:
@echo "Running target clean"
rm -f *.o
rm -f *.elf
rm -f *.bin
生成文件很简单。它的目标是从 test.s 文件创建 test.bin。
test.s 文件如下。我创建了 test.s 文件
.text
.syntax unified
.file "main.bc"
.def main;
.scl 2;
.type 32;
.endef
.globl main ; -- Begin function main
.p2align 1
.code16 ; @main
.thumb_func
main:
; %bb.0:
sub sp, #8
movs r0, #10
movs r1, #20
cmp r0, #21
str r0, [sp, #4]
str r1, [sp]
blo ($MBB0_2)
; %bb.1:
ldr r0, [sp, #4]
adds r0, #1
str r0, [sp, #4]
$MBB0_2:
add sp, #8
bx lr
; -- End function
到这里为止,一切都很顺利。在这里,我执行了 make.exe 来创建 test.bin,但出现如下错误。
不知道llc.exe生成的.s文件是不是不是cortex-m3的格式。
有人可以帮助我吗?我想知道问题的原因是什么。
谢谢阅读。
- - - - - - - - - - - - - - - - 更新 - - - - - - - - - -----------------
原始代码如下。代码只是为了测试目的而编写的。
void main()
{
int a = 10;
int b = 20;
if ( a > b) a ++;
}
位码如下。位码是手动生成的。
define void @main()
{
%1 = alloca i32, align 4
%2 = alloca i32, align 4
store i32 10, i32* %1, align 4
store i32 20, i32* %2, align 4
%3 = load i32, i32* %1, align 4
%4 = load i32, i32* %2, align 4
%5 = icmp ugt i32 %3, %4
br i1 %5, label %6, label %9
;%6
%7 = load i32, i32* %1, align 4
%8 = add nsw i32 %7, 1
store i32 %8, i32* %1, align 4
br label %9
;%9
ret void
}