如何配置gcc默认使用-no-pie?

2023-12-21

我想在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。


我想只是不要配置 gcc--enable-default-pie.

请参阅这篇博文:http://nanxiao.me/en/gccs-enable-enable-default-pie-option-make-you-stuck-at-relocation-r_x86_64_32s-against-error/ http://nanxiao.me/en/gccs-enable-enable-default-pie-option-make-you-stuck-at-relocation-r_x86_64_32s-against-error/,以及默认启用饼图的 Arch 补丁:.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何配置gcc默认使用-no-pie? 的相关文章

随机推荐