[英]Can't assemble the .s file that was generated by llc using arm-none-eabi-as?
我的英語水平很差,因為我的母語不是英語。
我使用 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
makefile 很簡單。 它的目標是從 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
}
感謝 Frant 的評論,我解決了這個問題。
我更新了比特碼文件,如下所示。
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"
}
我將 llc 命令更新為如下。
llc -mtriple=arm-none-eabi -march=thumb -mattr=thumb2 -mcpu=cortex-m3 main.bc -o test.s
結果 .s 文件正確生成。
感謝您對我的問題感興趣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.