“在创建共享库时,不能使用针对'.bss的重定位R_X86_64_32S" [英] "relocation R_X86_64_32S against `.bss' can not be used when making a shared object”
问题描述
我绝对是绿色的,但是在上课时,老师给了他他写给我们的文件,供我们运行,然后它运行良好,但是当我尝试在家做时(我在VirtualBox上使用Linux)并使用:
I'm absolutely green in this but during classes, teacher gave us file he wrote just for us to run it and it worked fine then, but when I try to do it at home (I use Linux on VirtualBox) and use:
nasm -f elf64 hello.asm -o hello.o
gcc hello.o -o hello
我收到一个错误消息:在创建共享库时,无法对.bss使用重定位R_X86_64_32S;使用-fPIC重新编译."有人可以解释一下如何使其正常工作吗?
I get an error "relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC". Can someone please explain what to do to make it work?
global main
extern printf
section .data
napis: db ' Hello world! - po raz %ld',10,0
liczba_iteracji: equ 5
section .bss
licznik: resb 1
section .text
main:
push rbp
mov rbp,rsp
mov byte [licznik],0
petla: ;naiwna!
inc byte [licznik]
mov rdi, qword napis
mov rsi, qword [licznik]
mov rax, 0
call printf
cmp byte [licznik],liczba_iteracji
jnz petla
mov rsp,rbp
pop rbp
mov rax,1 ;SYS_EXIT
mov rbx,0
int 80h
推荐答案
You need to make certain you're writing position independent code. The idea of PIC is that to make code truly position-independent, you need at least one level of indirection. That level of indirection is IP-relative addressing, and when that is not enough, you will need a second layer, the Global Offset Table or GOT.
在NASM中,您会找到 DEFAULT REL 指令很有用.
In NASM, you will find the DEFAULT REL directive(s) useful.
这篇关于“在创建共享库时,不能使用针对'.bss的重定位R_X86_64_32S"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!