我正在尝试编译和链接汇编程序。
汇编文件(main.asm):
.section .text
.global main
main:
mov $msg, %rdi
call printf
xor %rax, %rax
mov $80, %rdi
syscall
msg:
.ascii "hello world\n\0"
LD脚本:
ENTRY(main)
SECTIONS
{
. = 0x10000;
.text : {
*(.text)
}
}
编译命令(成功退出):
as -c main.asm -o main.o
链接命令:
ld main.o -o main -Tbin.ld -lc
最后一个命令失败,并出现未定义的参考错误*printf*
和其他相关符号:
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: out/main: section .tdata lma 0xaef90 adjusted to 0xaefd0
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(printf_fp.o): in function `__printf_fp_l':
(.text+0x4d0): undefined reference to `__unordtf2'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: (.text+0x501): undefined reference to `__unordtf2'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: (.text+0x523): undefined reference to `__letf2'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(printf_fphex.o): in function `__printf_fphex':
(.text+0x94): undefined reference to `__unordtf2'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: (.text+0xce): undefined reference to `__unordtf2'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: (.text+0xea): undefined reference to `__letf2'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(iofclose.o): in function `_IO_new_fclose.cold.0':
(.text.unlikely+0x35): undefined reference to `_Unwind_Resume'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(iofclose.o):(.data.rel.local.DW.ref.__gcc_personality_v0[DW.ref.__gcc_personality_v0]+0x0): undefined reference to `__gcc_personality_v0'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(iofflush.o): in function `_IO_fflush.cold.0':
(.text.unlikely+0x35): undefined reference to `_Unwind_Resume'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(iofputs.o): in function `_IO_fputs.cold.0':
(.text.unlikely+0x35): undefined reference to `_Unwind_Resume'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(iofwrite.o): in function `_IO_fwrite.cold.0':
(.text.unlikely+0x35): undefined reference to `_Unwind_Resume'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(iogetdelim.o): in function `_IO_getdelim.cold.0':
(.text.unlikely+0x35): undefined reference to `_Unwind_Resume'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(wfileops.o): in function `_IO_wfile_underflow.cold.2':
(.text.unlikely+0x37): undefined reference to `_Unwind_Resume'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib/libc.a(fileops.o):(.text.unlikely+0x38): more undefined references to `_Unwind_Resume' follow
如何成功链接并运行该程序?