OSX NASM位置无关代码 [英] OSX NASM Position independent code

查看:142
本文介绍了OSX NASM位置无关代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

最近,我有一个任务要在MACOS下建立一个项目.挣扎于许多分歧,我终于走到了尽头,一切似乎都奏效,但一个问题困扰着我.

该项目具有如下的汇编(NASM)代码:

Hi.

Recently I''ve got a task to build a project under MACOS. Struggling many differences, I finaly got to an end, and everything seems to work, but one issue bothers me.

The project has assembly (NASM) code like this:

SECTION .rodata align=16

ALIGN 16
const_w05: times 8 dw 5


SECTION .text

ALIGN16
_some_function_sse2:
...
pmullw      xmm1,   [rel const_w05]
...
ret



现在谈到链接时,出现以下错误:
ld:(_ some_function_sse2)中使用的绝对寻址(也许是-mdynamic-no-pic),...在可滑动图像中不允许.使用"-read_only_relocs抑制"来启用文本重定位

因此,在阅读大量信息之后,我没有发现建议的选项 -read_only_relocs抑制的错误.该项目已建立并运行.

但是,如果共享库加载到不同的内存位置,恐怕它是不正确的,并且可能无法正常工作.

顺便说一句:该项目是一个共享库(动态库).

PS2:一切都建立在LINUX上,没有任何此类错误.



Now whe it comes to linking, I get the following error:
ld: absolute addressing (perhaps -mdynamic-no-pic) used in (_some_function_sse2) from ... not allowed in slidable image. Use ''-read_only_relocs suppress'' to enable text relocs

So reading lot of information on this, I had nothing bug put the suggested option -read_only_relocs suppress. The project was built and worked.

But I''m afraid it isn''t correct and may not work if the shared object loads in different memory location.

BTW: The project is a shared object (dynamic library).

PS2: Everything builds on LINUX with no such errors.

推荐答案

但是为什么要使用rel前缀?常量数据可能是可重定位的,因此可以在其周围移动,这将破坏相对寻址.如果删除它,会发生什么?
But why use the rel prefix? Probably the constant data is relocatable and could therefor be moved around which would break the relative addressing. What happens if you remove it?


如果您将绝对地址更改为相对地址,该怎么办?即:.\ data \ mdynamic-no-pic.jpg或类似的东西.
What if you change your absolute address to relative address. ie: .\data\mdynamic-no-pic.jpg or something like that.


这篇关于OSX NASM位置无关代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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