我想在 Linux 上编译以下程序:
.global _start
.text
_start:
mov $1, %rax
mov $1, %rdi
mov $msg, %rsi
mov $13, %rdx
syscall
mov $60, %rax
xor %rdi, %rdi
syscall
msg:
.ascii "Hello World!\n"
但是,它给了我以下链接器错误:
$ gcc -nostdlib hello.s
/usr/bin/ld: /tmp/ccMNQrOF.o: relocation R_X86_64_32S against `.text' 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 returned 1 exit status
我认为它不起作用的原因是因为 gcc-pie
默认使用生成共享对象。因此,使用-no-pie
修复它:
$ gcc -no-pie -nostdlib hello.s
$ ./a.out
Hello World!
如何将 gcc 配置为-no-pie
默认使用?我正在使用 Arch Linux。