Position Independent Code pointing to wrong address

后端 未结 1 1747
独厮守ぢ
独厮守ぢ 2021-01-15 04:00

I have a small example program written in NASM(2.11.08) targeting the macho64 architecture. I\'m running OSX 10.10.3:

bits 64

section .data

    msg1    db          


        
相关标签:
1条回答
  • 2021-01-15 04:14

    IDK about the Mach-o ABI, but if it's the same as the SystemV x86-64 ABI GNU/Linux uses, then I think your problem is that you need to clear eax to tell a varargs function like printf that there are zero FP.

    Also, lea rdi, [rel msg1] would be a much better choice. As it stands, your code is only position-independent within the low 32bits of virtual address space, because you're truncating the pointers to 32bits.

    It appears NASM has a bug. This same problem came up again: NASM 2 lines of db (initialized data) seemingly not working. There, the OP confirmed that the data was present, but labels were wrong, and is hopefully reporting it upstream.

    0 讨论(0)
提交回复
热议问题