“在创建共享库时,不能使用针对'.bss的重定位R_X86_64_32S" [英] "relocation R_X86_64_32S against `.bss' can not be used when making a shared object”

查看:161
本文介绍了“在创建共享库时,不能使用针对'.bss的重定位R_X86_64_32S"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对是绿色的,但是在上课时,老师给了他他写给我们的文件,供我们运行,然后它运行良好,但是当我尝试在家做时(我在V​​irtualBox上使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆