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). The command that I used to create test.s is as below.
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.
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. It's goal is to create test.bin from test.s file.
test.s file is as below. I created test.s file
.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.
I don't know if the .s file that generated by llc.exe is not format of 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.
I updated bitcode file as below.
And I updated llc command to as below.
The result .s file is generated correctly.
Thanks for your interest in my problem.