LLVM/clang输出到MIPS,但在SPIM中不工作
给定文件LLVM/clang输出到MIPS,但在SPIM中不工作,clang,llvm,mips,simulator,spim,Clang,Llvm,Mips,Simulator,Spim,给定文件 #include <stdio.h> int main() { printf("hello world\n"); return 0; } 不幸的是,当我尝试在我信任的SPIM MIPS模拟器中运行它时,我发现SPIM对象几乎覆盖了它的每一行。不仅“.Section.mdebug.abi32”行,而且 格式为“.cfi*”的任何行——甚至更令人困惑的是(因为在我看来它像MIPS…)行“lui$2,%hi(u gnu_local_gp)”被反对
#include <stdio.h>
int main() {
printf("hello world\n");
return 0;
}
不幸的是,当我尝试在我信任的SPIM MIPS模拟器中运行它时,我发现SPIM对象几乎覆盖了它的每一行。不仅“.Section.mdebug.abi32”行,而且
格式为“.cfi*”的任何行——甚至更令人困惑的是(因为在我看来它像MIPS…)行“lui$2,%hi(u gnu_local_gp)”被反对
我正在寻找一些关于SPIM和LLVM处理的不同风格的MIPS的信息,或者有人给出一个我可以运行的MIPS模拟器的示例,该模拟器接受LLVM正在生成的MIPS代码
.Section .mdebug.abi32
.previous
.file "hello.bc"
.text
.globl main
.align 2
.type main,@function
.set nomips16 # @main
.ent main
main:
.cfi_startproc
.frame $sp,32,$ra
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
# BB#0: # %entry
addiu $sp, $sp, -32
$tmp2:
.cfi_def_cfa_offset 32
sw $ra, 28($sp) # 4-byte Folded Spill
$tmp3:
.cfi_offset 31, -4
lui $2, %hi(__gnu_local_gp)
addiu $2, $2, %lo(__gnu_local_gp)
sw $2, 16($sp)
sw $zero, 24($sp)
lui $2, %hi($.str)
addiu $4, $2, %lo($.str)
jal printf
nop
addiu $2, $zero, 0
lw $ra, 28($sp) # 4-byte Folded Reload
addiu $sp, $sp, 32
jr $ra
nop
.set macro
.set reorder
.end main
$tmp4:
.size main, ($tmp4)-main
.cfi_endproc
.type $.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
$.str:
.asciz "hello world\n"
.size $.str, 13
LLVM中的Mips程序集打印机以GAS格式发出程序集(适合GNU汇编程序和兼容工具使用)。SPIM很可能无法读取。但是,如果SPIM可以读取Mips二进制文件,您可以尝试从LLVM发出一个对象文件,并让SPIM处理该文件
二进制文件更“通用”“因为它们必须被CPU本身理解。唉,每个汇编器通常都有自己的特定语法,只有它自己能理解,而且汇编器之间并不倾向于相互兼容,而且在基本问题上也存在分歧,如运算符顺序、标点符号语义、指令等等。Spim是一个简单的教学工具,不支持gnu汇编器。您可以尝试使用,它有各种真实MIPS处理器的完整模型。您可以在OVPsim上运行Linux,并且应该能够在该模拟Linux上运行clang生成的MIPS Linux可执行文件。如果您正在运行Linux,另一个途径是使用QEMU Linux用户模式模拟器进行MIPS。这就是我使用的基于叮当声的ELLCC工具链。()
.Section .mdebug.abi32
.previous
.file "hello.bc"
.text
.globl main
.align 2
.type main,@function
.set nomips16 # @main
.ent main
main:
.cfi_startproc
.frame $sp,32,$ra
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
# BB#0: # %entry
addiu $sp, $sp, -32
$tmp2:
.cfi_def_cfa_offset 32
sw $ra, 28($sp) # 4-byte Folded Spill
$tmp3:
.cfi_offset 31, -4
lui $2, %hi(__gnu_local_gp)
addiu $2, $2, %lo(__gnu_local_gp)
sw $2, 16($sp)
sw $zero, 24($sp)
lui $2, %hi($.str)
addiu $4, $2, %lo($.str)
jal printf
nop
addiu $2, $zero, 0
lw $ra, 28($sp) # 4-byte Folded Reload
addiu $sp, $sp, 32
jr $ra
nop
.set macro
.set reorder
.end main
$tmp4:
.size main, ($tmp4)-main
.cfi_endproc
.type $.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
$.str:
.asciz "hello world\n"
.size $.str, 13