这是在hello.s中的代码。
.data
hello_str:
.string "Hello, world!\n"
.set hello_str_length, . - hello_str - 1
.text
.globl main
.type main, @function
main:
movl $4, %eax
movl $1, %ebx
movl $hello_str, %ecx
movl $hello_str_length, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
.size main, . - main
我运行了gcc hello.s -o hello命令,但是出现了以下错误:
/usr/bin/ld: /tmp/cc6ILJpd.o: relocation R_X86_64_32 against '.data' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld返回了1个退出状态
然后我尝试运行gcc hello.s -fPIC -o hello,但它没有做任何事情,错误是相同的。
我做错了什么?Ubuntu 17.04,GCC 6.3.0。
int 80h
。64位模式应该使用syscall
(当然,参数不同)代替(虽然int 80h
在当前内核上通常可以工作,但它可能会在未来的Linux内核中消失,因为它并非正式存在)。 - Ped7g