简体   繁体   English

.rodata 搬迁相关问题

[英].rodata relocation related question

I'm trying to write a C program for a machine with no virtual memory(or OS to be more precise), and I'm running into some difficulties with the.rodata section, or more precisely the stuff that goes there.我正在尝试为没有虚拟内存(或更准确地说是操作系统)的机器编写 C 程序,并且我在 .rodata 部分遇到了一些困难,或者更准确地说是那里的东西。 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.出现的问题是,尽管在链接期间这些节位于明确定义的地址,但当程序开始执行时,它正在被重新定位。

eg: 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.例如:假设我的程序开始链接到从 0x1000 开始,当它被执行时,应该在 0x1000 的内容被重新定位在 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.话虽如此,我的问题是通常进入.rodata的东西是由编译器(gcc)“硬编码”的,我有点失去memory中的say.rodata常量,因为重定位和gcc硬编码它们的地址,以便它们获得绝对偏移量而不是相对偏移量。

Is there a way that I can get the.rodata constants to have a relative offset instead of an absolute one.有没有一种方法可以让 .rodata 常量具有相对偏移量而不是绝对偏移量。 And by relative, I mean relative to any active process registers?相对,我的意思是相对于任何活动的进程寄存器?

Depending on the architecture, It may be possible that the.rodata is arbitrally relocated to a specific memory area (a ROM for instance).根据架构,.rodata 可能会被任意重定位到特定的 memory 区域(例如 ROM)。 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.如果是这种情况,您必须使用 linker 脚本告诉链接将 your.rodata 部分放在正确的区域。 A good overview of how GCC linker scripts work can be found here:可以在这里找到 GCC linker 脚本如何工作的一个很好的概述:

http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html 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.此外,您可以在 Internet 上轻松找到许多特定于体系结构的链接脚本。

Hope that helped!希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM