MIPS Hello World程序段错误:链接警告是否为诱因?
MIPS程序编译警告与运行段错误的关联疑问
我编写了如下简单的MIPS程序:
.text globl __start __start: li $v0, 4004 li $a0, 1 la $a1, msg li $a2, 14 syscall li $v0, 4001 li $a0, 0 syscall .data msg: .asciiz "hello, world\n"
使用以下命令交叉编译并在QEMU中运行:
$ clang --target=mips-linux-gnu -nostdlib -static -fuse-ld=lld test.s -o a.out ld.lld: warning: *can't find matching R_MIPS_LO16 relocation for R_MIPS_GOT16* $ qemu-mips a.out Segmentation fault (core dumped)
我想确认这个编译警告是否与运行时的段错误有关。以下是生成的可执行文件相关信息:
可执行文件属性
$ file a.out a.out: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), statically linked, BuildID[xxHash]=0e7f55e2470ade0a, not stripped
反汇编结果
$ llvm-objdump -d a.out /tmp/a.out: file format elf32-mips Disassembly of section .text: 00020180 <__start>: 20180: 24 02 0f a4 addiu $2, $zero, 4004 20184: 24 04 00 01 addiu $4, $zero, 1 20188: 8f 85 80 18 lw $5, -32744($gp) 2018c: 24 06 00 0e addiu $6, $zero, 14 20190: 00 00 00 0c syscall 20194: 24 02 0f a1 addiu $2, $zero, 4001 20198: 24 04 00 00 addiu $4, $zero, 0 2019c: 00 00 00 0c syscall
补充测试
移除输出"hello, world"的系统调用后,程序可正常运行:
.text globl __start __start: li $v0, 4001 li $a0, 0 syscall .data msg: .asciiz "hello, world\n"
我预期原程序能打印"hello, world"并以返回码0退出,但实际运行出现段错误,特此询问该编译警告是否与段错误直接相关。
内容的提问来源于stack exchange,提问作者kjc
相关产品推荐
相关产品推荐

