[英]Can't assemble the .s file that was generated by llc using arm-none-eabi-as?
My English skill is poor because I'm not a native English speaker.我的英语水平很差,因为我的母语不是英语。
I compiled a bitcode using llc.exe and get a .s file (test.s).我使用 llc.exe 编译了一个位码并获得了一个 .s 文件(test.s)。 The command that I used to create test.s is as below.
我用来创建 test.s 的命令如下。
llc -march=thumb -mattr=thumb2 -mcpu=cortex-m3 main.bc -o test.s
Yes, my target board is cortex-m3 (stm32l series) and I created makefile as below to create .bin file.是的,我的目标板是 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
makefile is simple. makefile 很简单。 It's goal is to create test.bin from test.s file.
它的目标是从 test.s 文件创建 test.bin。
test.s file is as below. test.s 文件如下。 I created test.s file
我创建了 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
EveryThing went smoothly until here.一切都很顺利,直到这里。 Here I executed make.exe to create test.bin but I got a error as below.
在这里,我执行 make.exe 来创建 test.bin,但出现如下错误。
I don't know if the .s file that generated by llc.exe is not format of cortex-m3.不知道llc.exe生成的.s文件是不是cortex-m3的格式。
Could someone help me?有人可以帮助我吗? I want to know what cause of problem is.
我想知道问题的原因是什么。
Thanks for reading.谢谢阅读。
------------------------------- update ----------------------------------- - - - - - - - - - - - - - - - - 更新 - - - - - - - - - -----------------
Original code is as below.原始代码如下。 The code was write just test purpose.
代码只是为了测试目的而编写的。
void main()
{
int a = 10;
int b = 20;
if ( a > b) a ++;
}
The bitcode is as below.位码如下。 The bitcode was generated manually.
位码是手动生成的。
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
}
I solved this problem thanks for Frant's comment.感谢 Frant 的评论,我解决了这个问题。
I updated bitcode file as below.我更新了比特码文件,如下所示。
define void @main() #0
{
%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
}
attributes #0 =
{
norecurse nounwind readnone
"stack-protector-buffer-size"="8"
}
And I updated llc command to as below.我将 llc 命令更新为如下。
llc -mtriple=arm-none-eabi -march=thumb -mattr=thumb2 -mcpu=cortex-m3 main.bc -o test.s
The result .s file is generated correctly.结果 .s 文件正确生成。
Thanks for your interest in my problem.感谢您对我的问题感兴趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.