Aad*_*hah 6 configuration gcc gnu-assembler ld position-independent-code
我想在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"
Run Code Online (Sandbox Code Playgroud)
但是,它给了我以下链接器错误:
$ 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
Run Code Online (Sandbox Code Playgroud)
我认为它不起作用的原因是 gcc-pie
默认使用生成共享对象。因此,使用-no-pie
修复它:
$ gcc -no-pie -nostdlib hello.s
$ ./a.out
Hello World!
Run Code Online (Sandbox Code Playgroud)
如何配置 gcc-no-pie
默认使用?我正在使用 Arch Linux。
我想只是不要用--enable-default-pie
.
请参阅此博文:http://nanxiao.me/en/gccs-enable-enable-default-pie-option-make-you-stuck-at-relocation-r_x86_64_32s-against-error/以及启用饼图的 Arch 补丁默认情况下:https://git.archlinux.org/svntogit/packages.git/commit/trunk?h=packages/gcc&id=5936710c764016ce306f9cb975056e5b7605a65b。
归档时间: |
|
查看次数: |
19839 次 |
最近记录: |