.rodata搬迁相关问题
我正在尝试为没有虚拟内存(或更准确地说是操作系统)的机器编写一个 C 程序,并且我在 .rodata 部分(或更准确地说是那里的内容)方面遇到了一些困难。出现的问题是,尽管在链接期间这些节被定位在明确定义的地址处,但当程序进入执行时,它正在被重新定位。
例如:假设我的程序启动链接到从 0x1000 开始,当它被执行时,应该在 0x1000 处的内容被重新定位到 0xff1000 处。
话虽这么说,我的问题是,通常进入 .rodata 的内容是由编译器(gcc)“硬编码”的,并且由于重定位和 gcc 对其地址进行硬编码,我有点丢失了内存中的 .rodata 常量,以便它们获取绝对偏移量而不是相对偏移量。
有没有一种方法可以让 .rodata 常量具有相对偏移量而不是绝对偏移量。我所说的相对,是指相对于任何活动进程寄存器?
I'm trying to write a C program for a machine with no virtual memory(or O.S. to be more precise), and I'm running into some difficulties with the .rodata section, or more precisely the stuff that goes there. The problem arises that although the sections are positioned at well defined addresses during linking, when the program goes into execution, it is being relocated.
e.g.: Let's say that my program starts is linked to start at 0x1000, when it is being executed it what should be at 0x1000 is relocated at 0xff1000.
These being said, my problem is that the stuff that usually goes into .rodata are "hardcoded" by the compiler(gcc), and i kinda lose said .rodata constants in memory because of the relocation and the gcc hardcoding their addresses so that they get an absolute offset instead of a relative one.
Is there a way that I can get the .rodata constants to have a relative offset instead of an absolute one. And by relative, I mean relative to any active process registers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据架构的不同,.rodata 可能会被任意重定位到特定的内存区域(例如 ROM)。此类信息可以在您的机器数据表中找到。
如果遇到这种情况,您必须使用链接器脚本告诉链接将 .rodata 部分放在正确的区域中。
有关 GCC 链接器脚本如何工作的详细概述,请参见:
http ://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html
此外,您可以在互联网上轻松找到许多特定于体系结构的链接脚本。
希望有帮助!
Depending on the architecture, It may be possible that the .rodata is arbitrally relocated to a specific memory area (a ROM for instance). This kind of information can be found in your machine datasheet.
If you are in this case, you have to tell the link to put your .rodata section in the right area, using a linker script.
A good overview of how GCC linker scripts work can be found here:
http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html
Moreover, you can easily find a lot of architecture-specific link scripts on the internet.
Hope that helped!