How to force nasm to address variables position-independent?

无人久伴 提交于 2020-01-04 05:35:13

问题


How to tell NASM (or LD) to process labels in a way that will make the segment position-independent?

The segment is going to be moved from one file to another and I want it to work properly on any position in any file.

Here is the code that illustrates my problem:

section .text
...
message: db 'hello world!',0x00
...
mov rax,SYSCALL_WRITE
mov rdi,STDOUT
mov rsi,message
mov rdx,13
syscall

In the orginal executable it prints "Hello world!", but when the segment is moved to another elf, it prints some random bytes.

来源:https://stackoverflow.com/questions/34288482/how-to-force-nasm-to-address-variables-position-independent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!